首页 > 代码库 > CentOS7使用ssh不能登录,报错:Read from socket failed: Connection reset by peer

CentOS7使用ssh不能登录,报错:Read from socket failed: Connection reset by peer

使用xshell登录CentOS7,不能登录,使用另外一台Linux主机,telent 22端口是同的,ssh连接报以下错误:

Read from socket failed: Connection reset by peer

查看不能登录主机的日志

# cat /var/log/messages


Dec 15 19:38:27 localhost dbus-daemon: dbus[874]: [system] Successfully activated service ‘org.freedesktop.nm_dispatcher‘

Dec 15 19:38:27 localhost systemd: Started Network Manager Script Dispatcher Service.

Dec 15 19:38:27 localhost nm-dispatcher: Dispatching action ‘dhcp4-change‘ for eno16777736

Dec 15 19:38:33 localhost sshd[3125]: error: Could not load host key: /etc/ssh/ssh_host_rsa_key

Dec 15 19:38:33 localhost sshd[3125]: error: Could not load host key: /etc/ssh/ssh_host_ecdsa_key

Dec 15 19:38:33 localhost sshd[3125]: error: Could not load host key: /etc/ssh/ssh_host_ed25519_key

Dec 15 19:39:42 localhost sshd[3127]: error: Could not load host key: /etc/ssh/ssh_host_rsa_key

Dec 15 19:39:42 localhost sshd[3127]: error: Could not load host key: /etc/ssh/ssh_host_ecdsa_key

Dec 15 19:39:42 localhost sshd[3127]: error: Could not load host key: /etc/ssh/ssh_host_ed25519_key

Dec 15 19:44:56 localhost sshd[3136]: error: Could not load host key: /etc/ssh/ssh_host_ecdsa_key

Dec 15 19:44:56 localhost sshd[3136]: error: Could not load host key: /etc/ssh/ssh_host_ed25519_key

Dec 15 19:47:03 localhost sshd[3138]: error: Could not load host key: /etc/ssh/ssh_host_ecdsa_key

Dec 15 19:47:03 localhost sshd[3138]: error: Could not load host key: /etc/ssh/ssh_host_ed25519_key


找到问题所在,用如下命令

ssh-keygen -t dsa -P ‘‘ -f  /etc/ssh/ssh_host_dsa_key  

ssh-keygen -t rsa -P ‘‘ -f  /etc/ssh/ssh_host_rsa_key 


分别把这两个密钥生成就可以正常启动和使用 ssh了 。到此问题就解决完了。

service ssh restart

重启下服务,这个时候就可以连接了。


总结:遇到问题,不要手足无措,首先看看系统提示和日志,好好分析以下。不行立马百度或Google。

本文出自 “汪立明” 博客,请务必保留此出处http://afterdawn.blog.51cto.com/7503144/1922651

CentOS7使用ssh不能登录,报错:Read from socket failed: Connection reset by peer