ssh 提示Connection closed by * 的解决方案

使用ssh方式链接linux系统时,发现一直上报这个错误,重启了sshd服务以后,只能登录一次就没法登陆:linux

 # 出现问题的机器执行
 [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)? 

再次尝试链接一直报错:web

 [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.

什么错误,这就要详细的分析了。究竟是哪儿出的问题呢?shell

根据思路来,先看log:从log能够看出,出错的缘由很明显,就是加密文件权限有问题了,接下来就去查看和改动文件权限。vim

 [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 <keycode>'to makeit known.
 Jan 1511:25:05 localhost kernel: atkbd.c: Unknown key released (translated set2, code 0x0 on isa0060/serio0).
 Jan 1511:25:05 localhost kernel: atkbd.c: Use 'setkeycodes 00 <keycode>'to makeit known.
 Jan 1511:25:08 localhost kernel: __ratelimit: 14688callbacks suppressed

在/etc/ssh目录下查看,的确是文件的问题,不知道什么缘由,文件秘钥文件被删除了,按照别的系统的文件拷贝过来便可:centos

 [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/目录下,包括不一样算法的公钥,私钥app

ssh 按如下顺序从如下源获取配置数据:运维

一、命令行选项ssh

二、用户的配置文件(〜/.ssh/config)

三、系统范围的配置文件(/etc/ssh/ssh_config)

若是文章有任何错误欢迎不吝赐教,其次你们有任何关于运维的疑难杂问,也欢迎和你们一块儿交流讨论。关于运维学习、分享、交流,笔者开通了微信公众号【运维猫】,感兴趣的朋友能够关注下,欢迎加入,创建属于咱们本身的小圈子,一块儿学运维知识。群主还经营一家猫小铺饰品店,喜欢的小伙伴欢迎👏前来下单。



扫描二维码

获取更多精彩

运维猫公众号

有须要技术交流的小伙伴能够加我微信,期待与你们共同成长,本人微信:

扫描二维码

添加私人微信

运维猫博主


扫码加微信


最近有一些星友咨询我知识星球的事,我也想继续在星球上发布更优质的内容供你们学习和探讨。运维猫公众号平台致力于为你们提供免费的学习资源,知识星球主要致力于即将入坑或者已经入坑的运维行业的小伙伴。

点击阅读原文  查看更多精彩内容!!!


本文分享自微信公众号 - 运维猫(centos15)。
若有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一块儿分享。

相关文章
相关标签/搜索