AIOps 一场颠覆传统运维的盛筵
2480
2022-11-06
ssh 提示Connection closed by * 的解决方案
使用ssh方式连接linux系统时,发现一直上报这个错误,重启了sshd服务之后,只能登陆一次就无法登录:
# 出现问题的机器执行 [root@localhost ~]# service sshd restart # 其他机器链接过去,只能连接一次就接着会报错 [root@localhost ~]# ssh root@172.17.0.84 The authenticity of host '172.17.0.84 (172.17.0.84)'can't be established. RSA key fingerprint is f7:ce:40:fd:7c:d5:c8:64:2a:b9:bb:00:42:6b:25:9f. Are you sure you want to continue connecting (yes/no)?
再次尝试连接一直报错:
[root@localhost ~] sshroot@172.17.0.84 Connection closed by 172.17.0.84 port 22 [root@localhost ~] sshroot@172.17.0.84 Connection closed by 172.17.0.84 port 22 [root@localhost ~] sshroot@172.17.0.84 Connection closed by 172.17.0.84 port 22
刚开始还以为是端口以及防火墙的问题呢,通过查看和关闭,并没有发现
[root@localhost ~]# nc -w 1 172.17.0.84 22 < dev/null && echo "tcp port ok" SSH-2.0-OpenSSH_5.3 tcp port ok
[root@localhost ~]# service iptables status iptables: Firewall is not running.
什么错误,这就要详细的分析了。到底是哪儿出的问题呢?
根据思路来,先看log:从log可以看出,出错的原因很明显,就是加密文件权限有问题了,接下来就去查看和改动文件权限。
[root@localhost ~]# vim var/log/messages Jan 1511:24:53 localhost kernel: TCP: time wait bucket table overflow Jan 1511:24:57 localhost sshd[1740]: error: Could not load host key: etc/ssh/ssh_host_rsa_key Jan 1511:24:57 localhost sshd[1740]: error: Could not load host key: etc/ssh/ssh_host_dsa_key Jan 1511:24:58 localhost kernel: __ratelimit: 14450callbacks suppressed Jan 1511:24:58 localhost kernel: TCP: time wait bucket table overflow Jan 1511:24:58 localhost kernel: TCP: time wait bucket table overflow Jan 1511:24:58 localhost kernel: TCP: time wait bucket table overflow Jan 1511:24:58 localhost kernel: TCP: time wait bucket table overflow Jan 1511:24:58 localhost kernel: TCP: time wait bucket table overflow Jan 1511:24:58 localhost kernel: TCP: time wait bucket table overflow Jan 1511:24:58 localhost kernel: TCP: time wait bucket table overflow Jan 1511:24:58 localhost kernel: TCP: time wait bucket table overflow Jan 1511:24:58 localhost kernel: TCP: time wait bucket table overflow Jan 1511:24:58 localhost kernel: TCP: time wait bucket table overflow Jan 1511:25:01 localhost sshd[1744]: error: Could not load host key: etc/ssh/ssh_host_rsa_key Jan 1511:25:01 localhost sshd[1744]: error: Could not load host key: etc/ssh/ssh_host_dsa_key Jan 1511:25:03 localhost kernel: __ratelimit: 14573callbacks suppressed Jan 1511:25:03 localhost kernel: TCP: time wait bucket table overflow Jan 1511:25:03 localhost kernel: TCP: time wait bucket table overflow Jan 1511:25:03 localhost kernel: TCP: time wait bucket table overflow Jan 1511:25:03 localhost kernel: TCP: time wait bucket table overflow Jan 1511:25:03 localhost kernel: TCP: time wait bucket table overflow Jan 1511:25:03 localhost kernel: TCP: time wait bucket table overflow Jan 1511:25:03 localhost kernel: TCP: time wait bucket table overflow Jan 1511:25:03 localhost kernel: TCP: time wait bucket table overflow Jan 1511:25:03 localhost kernel: TCP: time wait bucket table overflow Jan 1511:25:03 localhost kernel: TCP: time wait bucket table overflow Jan 1511:25:05 localhost kernel: atkbd.c: Unknown key pressed (translated set2, code 0x0 on isa0060/serio0). Jan 1511:25:05 localhost kernel: atkbd.c: Use 'setkeycodes 00
在/etc/ssh目录下查看,的确是文件的问题,不知道什么原因,文件秘钥文件被删除了,按照别的系统的文件拷贝过来即可:
[root@localhost ssh]# ls -Zd * -rw-------. root root system_u:object_r:etc_t:s0 moduli -rw-r--r--. root root system_u:object_r:etc_t:s0 ssh_config -rw-------root root ? sshd_config -rw-------root root ? ssh_host_dsa_key -rw-r--r--root root ? ssh_host_dsa_key.pub -rw-------root root ? ssh_host_key -rw-r--r--root root ? ssh_host_key.pub -rw-------root root ? ssh_host_rsa_key -rw-r--r--root root ? ssh_host_rsa_key.pub
总结:
默认情况下密钥对都在/etc/ssh/目录下,包括不同算法的公钥,私钥
ssh 按以下顺序从以下源获取配置数据:
1、命令行选项
2、用户的配置文件(〜/.ssh/config)
3、系统范围的配置文件(/etc/ssh/ssh_config)
扫码
发表评论
暂时没有评论,来抢沙发吧~