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

时间:2023-03-10 07:46:19
ssh 提示Connection closed by * 的解决方案

  使用ssh方式连接linux系统时,发现一直上报这个错误:

Connection closed by 192.168.3.71 port 22 刚开始还以为是端口被防火墙禁止了呢,通过关闭和查看,并没有发现

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

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

Mar 24 09:35:50 sshd[3306]: error: Permissions 0777 for '/etc/ssh/ssh_host_rsa_key' are too open.
Mar 24 09:35:50 sshd[3306]: error: It is required that your private key files are NOT accessible by others.
Mar 24 09:35:50 sshd[3306]: error: This private key will be ignored.
Mar 24 09:35:50 sshd[3306]: error: key_load_private: bad permissions
Mar 24 09:35:50 sshd[3306]: error: Could not load host key: /etc/ssh/ssh_host_rsa_key
Mar 24 09:35:50 sshd[3306]: error: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Mar 24 09:35:50 sshd[3306]: error: @ WARNING: UNPROTECTED PRIVATE KEY FILE! @
Mar 24 09:35:50 sshd[3306]: error: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Mar 24 09:35:50 sshd[3306]: error: Permissions 0777 for '/etc/ssh/ssh_host_dsa_key' are too open.
Mar 24 09:35:50 sshd[3306]: error: It is required that your private key files are NOT accessible by others.
Mar 24 09:35:50 sshd[3306]: error: This private key will be ignored.
Mar 24 09:35:50 , sshd[3306]: error: key_load_private: bad permissions
Mar 24 09:35:50 , sshd[3306]: error: Could not load host key: /etc/ssh/ssh_host_dsa_key
Mar 24 09:35:50 , sshd[3306]: error: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Mar 24 09:35:50 , sshd[3306]: error: @ WARNING: UNPROTECTED PRIVATE KEY FILE! @
Mar 24 09:35:50 , sshd[3306]: error: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Mar 24 09:35:50 , sshd[3306]: error: Permissions 0777 for '/etc/ssh/ssh_host_ecdsa_key' are too open.
Mar 24 09:35:50 , sshd[3306]: error: It is required that your private key files are NOT accessible by others.
Mar 24 09:35:50 , sshd[3306]: error: This private key will be ignored.
Mar 24 09:35:50 , sshd[3306]: error: key_load_private: bad permissions
Mar 24 09:35:50 , sshd[3306]: error: Could not load host key: /etc/ssh/ssh_host_ecdsa_key
Mar 24 09:35:50 , sshd[3306]: error: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Mar 24 09:35:50 , sshd[3306]: error: @ WARNING: UNPROTECTED PRIVATE KEY FILE! @

  在/etc/ssh目录下查看,的确是文件权限有问题,不知道什么原因,文件权限被改成了777,按照别的系统的文件权限,修改成下面的即可:

-rw-r--r--    root root  1月   : moduli
-rw-r--r-- root root 1月 : ssh_config
-rw-r--r-- root root 3月 : sshd_config
-rw------- root root 3月 : ssh_host_dsa_key
-rw-r--r-- root root 3月 : ssh_host_dsa_key.pub
-rw------- root root 3月 : ssh_host_ecdsa_key
-rw-r--r-- root root 3月 : ssh_host_ecdsa_key.pub
-rw------- root root 3月 : ssh_host_ed25519_key
-rw-r--r-- root root 3月 : ssh_host_ed25519_key.pub
-rw------- root root 3月 : ssh_host_rsa_key
-rw-r--r-- root root 3月 : ssh_host_rsa_key.pub
-rw-r--r-- root root 3月 : ssh_import_id