使用ssh方式鏈接linux系統時,發現一直上報這個錯誤,重啓了sshd服務以後,只能登錄一次就沒法登陸:linux
# 出現問題的機器執行
[root@localhost ~]# service sshd restart
# 其餘機器連接過去,只能鏈接一次就接着會報錯
[root@localhost ~]# ssh root@172.17.0.84
The authenticity of host '172.17.0.84 (172.17.0.84)'can't be established.
RSA key fingerprint is f7:ce:40:fd:7c:d5:c8:64:2a:b9:bb:00:42:6b:25:9f.
Are you sure you want to continue connecting (yes/no)?
再次嘗試鏈接一直報錯:web
[root@localhost ~] sshroot@172.17.0.84
Connection closed by 172.17.0.84 port 22
[root@localhost ~] sshroot@172.17.0.84
Connection closed by 172.17.0.84 port 22
[root@localhost ~] sshroot@172.17.0.84
Connection closed by 172.17.0.84 port 22
剛開始還覺得是端口以及防火牆的問題呢,經過查看和關閉,並無發現算法
[root@localhost ~]# nc -w 1 172.17.0.84 22 < /dev/null && echo "tcp port ok"
SSH-2.0-OpenSSH_5.3
tcp port ok
[root@localhost ~]# service iptables status
iptables: Firewall is not running.
什麼錯誤,這就要詳細的分析了。究竟是哪兒出的問題呢?shell
根據思路來,先看log:從log能夠看出,出錯的緣由很明顯,就是加密文件權限有問題了,接下來就去查看和改動文件權限。vim
[root@localhost ~]# vim /var/log/messages
Jan 1511:24:53 localhost kernel: TCP: time wait bucket table overflow
Jan 1511:24:57 localhost sshd[1740]: error: Could not load host key: /etc/ssh/ssh_host_rsa_key
Jan 1511:24:57 localhost sshd[1740]: error: Could not load host key: /etc/ssh/ssh_host_dsa_key
Jan 1511:24:58 localhost kernel: __ratelimit: 14450callbacks suppressed
Jan 1511:24:58 localhost kernel: TCP: time wait bucket table overflow
Jan 1511:24:58 localhost kernel: TCP: time wait bucket table overflow
Jan 1511:24:58 localhost kernel: TCP: time wait bucket table overflow
Jan 1511:24:58 localhost kernel: TCP: time wait bucket table overflow
Jan 1511:24:58 localhost kernel: TCP: time wait bucket table overflow
Jan 1511:24:58 localhost kernel: TCP: time wait bucket table overflow
Jan 1511:24:58 localhost kernel: TCP: time wait bucket table overflow
Jan 1511:24:58 localhost kernel: TCP: time wait bucket table overflow
Jan 1511:24:58 localhost kernel: TCP: time wait bucket table overflow
Jan 1511:24:58 localhost kernel: TCP: time wait bucket table overflow
Jan 1511:25:01 localhost sshd[1744]: error: Could not load host key: /etc/ssh/ssh_host_rsa_key
Jan 1511:25:01 localhost sshd[1744]: error: Could not load host key: /etc/ssh/ssh_host_dsa_key
Jan 1511:25:03 localhost kernel: __ratelimit: 14573callbacks suppressed
Jan 1511:25:03 localhost kernel: TCP: time wait bucket table overflow
Jan 1511:25:03 localhost kernel: TCP: time wait bucket table overflow
Jan 1511:25:03 localhost kernel: TCP: time wait bucket table overflow
Jan 1511:25:03 localhost kernel: TCP: time wait bucket table overflow
Jan 1511:25:03 localhost kernel: TCP: time wait bucket table overflow
Jan 1511:25:03 localhost kernel: TCP: time wait bucket table overflow
Jan 1511:25:03 localhost kernel: TCP: time wait bucket table overflow
Jan 1511:25:03 localhost kernel: TCP: time wait bucket table overflow
Jan 1511:25:03 localhost kernel: TCP: time wait bucket table overflow
Jan 1511:25:03 localhost kernel: TCP: time wait bucket table overflow
Jan 1511:25:05 localhost kernel: atkbd.c: Unknown key pressed (translated set2, code 0x0 on isa0060/serio0).
Jan 1511:25:05 localhost kernel: atkbd.c: Use 'setkeycodes 00 <keycode>'to makeit known.
Jan 1511:25:05 localhost kernel: atkbd.c: Unknown key released (translated set2, code 0x0 on isa0060/serio0).
Jan 1511:25:05 localhost kernel: atkbd.c: Use 'setkeycodes 00 <keycode>'to makeit known.
Jan 1511:25:08 localhost kernel: __ratelimit: 14688callbacks suppressed
在/etc/ssh目錄下查看,的確是文件的問題,不知道什麼緣由,文件祕鑰文件被刪除了,按照別的系統的文件拷貝過來便可:centos
[root@localhost ssh]# ls -Zd *
-rw-------. root root system_u:object_r:etc_t:s0 moduli
-rw-r--r--. root root system_u:object_r:etc_t:s0 ssh_config
-rw-------root root ? sshd_config
-rw-------root root ? ssh_host_dsa_key
-rw-r--r--root root ? ssh_host_dsa_key.pub
-rw-------root root ? ssh_host_key
-rw-r--r--root root ? ssh_host_key.pub
-rw-------root root ? ssh_host_rsa_key
-rw-r--r--root root ? ssh_host_rsa_key.pub
總結:微信
默認狀況下密鑰對都在/etc/ssh/目錄下,包括不一樣算法的公鑰,私鑰app
ssh 按如下順序從如下源獲取配置數據:運維
一、命令行選項ssh
二、用戶的配置文件(〜/.ssh/config)
三、系統範圍的配置文件(/etc/ssh/ssh_config)
若是文章有任何錯誤歡迎不吝賜教,其次你們有任何關於運維的疑難雜問,也歡迎和你們一塊兒交流討論。關於運維學習、分享、交流,筆者開通了微信公衆號【運維貓】,感興趣的朋友能夠關注下,歡迎加入,創建屬於咱們本身的小圈子,一塊兒學運維知識。羣主還經營一家貓小鋪飾品店,喜歡的小夥伴歡迎👏前來下單。
掃描二維碼
獲取更多精彩
運維貓公衆號
有須要技術交流的小夥伴能夠加我微信,期待與你們共同成長,本人微信:
掃描二維碼
添加私人微信
運維貓博主
掃碼加微信
最近有一些星友諮詢我知識星球的事,我也想繼續在星球上發佈更優質的內容供你們學習和探討。運維貓公衆號平臺致力於爲你們提供免費的學習資源,知識星球主要致力於即將入坑或者已經入坑的運維行業的小夥伴。
本文分享自微信公衆號 - 運維貓(centos15)。
若有侵權,請聯繫 support@oschina.cn 刪除。
本文參與「OSC源創計劃」,歡迎正在閱讀的你也加入,一塊兒分享。