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