前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ssh 提示Connection closed by * 的解决方案

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

作者头像
胡齐
发布2020-02-14 17:08:44
16.1K0
发布2020-02-14 17:08:44
举报
文章被收录于专栏:运维猫运维猫运维猫

使用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 <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目录下查看,的确是文件的问题,不知道什么原因,文件秘钥文件被删除了,按照别的系统的文件拷贝过来即可:

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

如果文章有任何错误欢迎不吝赐教,其次大家有任何关于运维的疑难杂问,也欢迎和大家一起交流讨论。

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2020-01-15,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 运维猫 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档