Fork me on GitHub

  使用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--   1 root root 300261 1月  18 22:15 moduli
-rw-r--r--   1 root root   1756 1月  18 22:15 ssh_config
-rw-r--r--   1 root root   2542 3月   7 10:12 sshd_config
-rw-------   1 root root    672 3月   7 10:12 ssh_host_dsa_key
-rw-r--r--   1 root root    615 3月   7 10:12 ssh_host_dsa_key.pub
-rw-------   1 root root    227 3月   7 10:12 ssh_host_ecdsa_key
-rw-r--r--   1 root root    187 3月   7 10:12 ssh_host_ecdsa_key.pub
-rw-------   1 root root    419 3月   7 10:12 ssh_host_ed25519_key
-rw-r--r--   1 root root    107 3月   7 10:12 ssh_host_ed25519_key.pub
-rw-------   1 root root   1675 3月   7 10:12 ssh_host_rsa_key
-rw-r--r--   1 root root    407 3月   7 10:12 ssh_host_rsa_key.pub
-rw-r--r--   1 root root    338 3月   7 10:12 ssh_import_id

 

posted on 2018-03-24 09:55  虚生  阅读(11648)  评论(0编辑  收藏  举报