打开两个虚拟机nodea nodeb,并设定ip,更改主机名称.
实验: 远程主机连接失败如何处理(客户端连接服务器失败)
服务器:[root@westoshost114 Desktop]# cd /etc/ssh
[root@westoshost114 ssh]# ls
moduli ssh_host_ecdsa_key ssh_host_rsa_key
ssh_config ssh_host_ecdsa_key.pub ssh_host_rsa_key.pub
ssh_config.d ssh_host_ed25519_key
sshd_config ssh_host_ed25519_key.pub
[root@westoshost114 ssh]# cat ssh_host_ecdsa_key.pub 服务端在root /ssh..中存储信息
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBO02qy9ZjMU6swV2lboEqYOAqmd/YICzaOcsDoPzneLt2Va0wgiROKcdFGJfsCx0mORKmmJDl/UZXOH8rgZ89bM=
[root@westoshost114 ssh]# rm -fr /etc/ssh/ssh_host_* 删除服务端公私密钥,并重启sshd服务
[root@westoshost114 ssh]# systemctl restart sshd
[root@westoshost114 ssh]# ls /etc/ssh/
moduli ssh_host_ecdsa_key ssh_host_rsa_key
ssh_config ssh_host_ecdsa_key.pub ssh_host_rsa_key.pub
ssh_config.d ssh_host_ed25519_key
sshd_config ssh_host_ed25519_key.pub
[root@westoshost114 ssh]# cat ssh_host_ecdsa_key.pub
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBGQKP6oyk6bYWwC8tLLOwC1CJMNzdJAuM7iJcooheaCkjvs8xDxvhs4BGl/OiCbFbl1M4Au9fCQP1efcc5BZOwo=
客户端:[root@westoshost214 Desktop]# ssh -l root 172.25.254.114 失败
[root@westoshost214 Desktop]# cat /root/.ssh/known_hosts 客户端在/root中存储认证信息
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /root/.ssh/known_hosts:2 错误发生位置 (因本地保存的服务器公钥与服务端已经更换了得密钥不匹配,导致身份认证失败.解决方案:按照提示行错误,删除文件中的报错行,重新获取密钥即可)
ECDSA host key for 172.25.254
[root@westoshost214 Desktop]# vim /root/.ssh/known_hosts
(删除文件中保存的公钥在重新获取公钥即可)
[root@westoshost214 Desktop]# ssh -l root 172.25.254.114成功
[root@westoshost214 Desktop]# cat /root/.ssh/known_hosts
172.25.254.114 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBGQKP6oyk6bYWwC8tLLOwC1CJMNzdJAuM7iJcooheaCkjvs8xDxvhs4BGl/OiCbFbl1M4Au9fCQP1efcc5BZOwo=

-f #后台运行
-o #指定连接参数


#### 三.sshd key认证 ####
#1.认证类型#

#3.对服务器加密#
ssh-key 认证
生成非对称加密密钥 私钥用来加密 公钥解锁
客户端214要连接服务器114
客户端设置:
# cd /root/.ssh/
# ls
authorized_keys known_hosts(指纹密码)
# rm -fr /root/.ssh/
# ssh-keygen -f(指定保存加密字符的文件) /root/.ssh/id_rsa -P(指定密码) ""(用密钥生成命令把密钥生成)
# ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.25.254.114(要锁谁就写谁)给我们服务器指定的用户上锁
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
root@172.25.254.114's password:
# ls
authorized_keys id_rsa id_rsa.pub known_hosts
客户端直接连接114 不需要密码
# ssh -l root 172.25.254.114
#### 四.sshd 安全优化参数详解 ####
什么是网桥?
用来连接两个不同网段的网络设备,使真机和虚拟机处在平行网
搭建网桥
[root@westos_student14 network-scripts]# virsh list
Id Name State
----------------------------------------------------
1 nodea running
[root@westos_student14 network-scripts]# virsh destroy nodea (关闭虚拟机)
Domain nodea destroyed
[root@westos_student14 ~]# westos-network common 对主机之前搭建好的网桥进行断开
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/19)
[root@westos_student14 ~]# cd /etc/sysconfig/network-scripts/
[root@westos_student14 network-scripts]# ls
ifcfg-enp0s25
[root@westos_student14 network-scripts]# vim ifcfg-enp0s25
DEVICE=enp0s25
BOOTPROTO=none
ONBOOT=yes
BRIDGE=br0
NAME=enp0s25
[root@westos_student14 network-scripts]# vim ifcfg-br0
DEVICE=br0
TYPE=Bridge
ONBOOT=yes
BOOTPROTO=none
IPADDR=172.25.254.14
PREFIX=24
NAME=br0
[root@westos_student14 network-scripts]# nmcli connection reload
[root@westos_student14 network-scripts]# nmcli connection up br0
Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/21)
[root@westos_student14 network-scripts]# nmcli connection up enp0s25
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/22)
[root@westos_student14 network-scripts]# bridge link 查看网桥连接
2: enp0s25: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master br0 state forwarding priority 32 cost 100
6: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 master virbr0 state disabled priority 32 cost 100
westos-vmctl start nodea
westos-vmctl view nodea 重启虚拟机 打开网卡
[root@westos_student14 network-scripts]# systemctl restart libvirtd (网桥不显示的话重启一下虚拟化)
Ping 172.25.254.14看是否能拼通。
本文介绍了在Linux环境中如何处理远程登录服务的问题,包括客户端和服务端的SSH密钥管理,解决身份认证失败的方法,以及如何通过ssh-keygen和ssh-copy-id实现无密码登录。此外,还涉及到sshd服务的安全优化参数和网桥配置,确保虚拟机与主机的网络互通。

3616

被折叠的 条评论
为什么被折叠?



