閱讀432 返回首頁    go iPhone_iPad_Mac_手機_平板_蘋果apple


SSH 登錄時出現如下錯誤:No supported key exchange algorithms__遠程登錄 (SSH)_Linux操作運維問題_雲服務器 ECS-阿裏雲

注意:本文相關配置及說明已在 CentOS 6.5 64 位操作係統中進行過測試。其它類型及版本操作係統配置可能有所差異,具體情況請參閱相應操作係統官方文檔。

 

,問題描述


,使用 ,SSH ,連接雲服務器 ,ECS ,(,Elastic Compute Server,) ,Linux ,服務器時,客戶端或服務端 ,secure ,日誌(可以通過 ,,,管理終端 ,進入係統查看)中可能會出現類似如下信息,導致無法正常連接服務器:

  • Read from socket failed: Connection reset by peer.
  • Connection closed by 192.168.0.1.
  • sshd error: could not load host key.
  • fatal: No supported key exchange algorithms [preauth].
  • DSA host key for 192.168.0.1 has changed and you have requested strict checking.
  • Host key verification failed.
  • ,ssh_exchange_identification: read: Connection reset by peer.

,問題原因


,該問題通常是由於 ,SSH ,服務相關的密鑰文件異常所致,可能的原因包括:

  • ,相關密鑰文件異常,比如文件損壞、被刪除或篡改等。
  • ,,相關密鑰文件權限配置異常,導致無法正確讀取。

,處理辦法


,要解決此問題,針對前述不同情況,請依次進行如下配置檢查或修改:

檢查文件權限

SSH 服務會對相關密鑰文件的權限進行檢查。比如,私鑰文件默認權限是 600,如果配置成 777 等其它權限,導致其它用戶也有讀取或修改權限。則 SSH 服務會認為該配置存在安全風險,進而導致客戶端連接失敗。
可以通過如下指令恢複相關文件的默認權限配置:

cd /etc/ssh/
chmod 600 ssh_host_*
chmod 644 *.pub

操作示意如下:

[root@centos]# cd /etc/ssh/
[root@centos]# chmod 600 ssh_host_*
[root@centos]# chmod 644 *.pub
[root@centos]# ll
total 156
-rw-------. 1 root root 125811 Nov 23  2013 moduli
-rw-r--r--. 1 root root   2047 Nov 23  2013 ssh_config
-rw-------  1 root root   3639 May 16 11:43 sshd_config
-rw-------  1 root root    668 May 20 23:31 ssh_host_dsa_key
-rw-r--r--  1 root root    590 May 20 23:31 ssh_host_dsa_key.pub
-rw-------  1 root root    963 May 20 23:31 ssh_host_key
-rw-r--r--  1 root root    627 May 20 23:31 ssh_host_key.pub
-rw-------  1 root root   1675 May 20 23:31 ssh_host_rsa_key
-rw-r--r--  1 root root    382 May 20 23:31 ssh_host_rsa_key.pub

檢查文件有效性

,如果參閱前述步驟,修改相關文件權限後,還是無法正常連接。由於 ,SSH ,服務在啟動時會自動重建丟失的密鑰文件。所以,也可以直接將相關文件刪除並重啟 ,SSH ,服務,讓相關文件自動生成。

相關指令如下:

cd /etc/ssh/
rm -rf ssh_host_*
service sshd restart

,操作示意如下:

[root@centos]# cd /etc/ssh/
[root@centos]# ll
total 156
-rw-------. 1 root root 125811 Nov 23  2013 moduli
-rw-r--r--. 1 root root   2047 Nov 23  2013 ssh_config
-rw-------  1 root root   3639 May 16 11:43 sshd_config
-rw-------  1 root root    672 May 20 23:08 ssh_host_dsa_key
-rw-r--r--  1 root root    590 May 20 23:08 ssh_host_dsa_key.pub
-rw-------  1 root root    963 May 20 23:08 ssh_host_key
-rw-r--r--  1 root root    627 May 20 23:08 ssh_host_key.pub
-rw-------  1 root root   1675 May 20 23:08 ssh_host_rsa_key
-rw-r--r--  1 root root    382 May 20 23:08 ssh_host_rsa_key.pub
[root@centos]# rm -rf ssh_host_*
[root@centos]# ll
total 132
-rw-------. 1 root root 125811 Nov 23  2013 moduli
-rw-r--r--. 1 root root   2047 Nov 23  2013 ssh_config
-rw-------  1 root root   3639 May 16 11:43 sshd_config
[root@centos]# service sshd restart
Stopping sshd:                                             [  OK  ]
Generating SSH1 RSA host key:                              [  OK  ]
Generating SSH2 RSA host key:                              [  OK  ]
Generating SSH2 DSA host key:                              [  OK  ]
Starting sshd:                                             [  OK  ]
[root@centos]# ll
total 156
-rw-------. 1 root root 125811 Nov 23  2013 moduli
-rw-r--r--. 1 root root   2047 Nov 23  2013 ssh_config
-rw-------  1 root root   3639 May 16 11:43 sshd_config
-rw-------  1 root root    668 May 20 23:16 ssh_host_dsa_key
-rw-r--r--  1 root root    590 May 20 23:16 ssh_host_dsa_key.pub
-rw-------  1 root root    963 May 20 23:16 ssh_host_key
-rw-r--r--  1 root root    627 May 20 23:16 ssh_host_key.pub
-rw-------  1 root root   1671 May 20 23:16 ssh_host_rsa_key
-rw-r--r--  1 root root    382 May 20 23:16 ssh_host_rsa_key.pub

,補充說明:,對於 ,Ubuntu ,、,Debain ,類操作係統,修複指令如下:

sudo rm -r /etc/ssh/ssh*key
sudo dpkg-reconfigure openssh-server

,如果還有問題,可以參閱,雲服務器 ECS Linux SSH 無法登錄問題排查指引做進一步排查分析。

,更多信息


 

,如果問題還未能解決,請聯係,,,售後技術支持,。

最後更新:2016-07-12 15:24:19

  上一篇:go 雲服務器 ECS Linux SSH 啟用 UseDNS 導致連接速度變慢__遠程登錄 (SSH)_Linux操作運維問題_雲服務器 ECS-阿裏雲
  下一篇:go SSH 服務啟動時出現如下錯誤:must be owned by root and not group or word-writable__遠程登錄 (SSH)_Linux操作運維問題_雲服務器 ECS-阿裏雲