歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> SSH登陸之忽略known_hosts文件

SSH登陸之忽略known_hosts文件

日期:2017/2/28 15:54:11   编辑:Linux教程

在平時工作中,有時候需要SSH登陸到別的Linux主機上去,但有時候SSH登陸會被禁止,並彈出如下類似提示:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!Someone could be eavesdropping on you right now (man-in-the-middle attack)!It is also possible that the RSA host key has just been changed.The fingerprint for the RSA key sent by the remote host is36:68:a6:e6:43:34:6b:82:d7:f4:df:1f:c2:e7:37:cc.Please contact your system administrator.Add correct host key in /u/xlian008/.ssh/known_hosts to get rid of this message.Offending key in /u/xlian008/.ssh/known_hosts:2RSA host key for 135.1.35.130 has changed and you have requested strict checking.Host key verification failed.

比較奇怪,於是研究了一下。
ssh會把你每個你訪問過計算機的公鑰(public key)都記錄在~/.ssh/known_hosts。當下次訪問相同計算機時,OpenSSH會核對公鑰。如果公鑰不同,OpenSSH會發出警告, 避免你受到DNS Hijack之類的攻擊。我在上面列出的情況,就是這種情況。

原因:一台主機上有多個Linux系統,會經常切換,那麼這些系統使用同一ip,登錄過一次後就會把ssh信息記錄在本地的~/.ssh/known_hsots文件中,切換該系統後再用ssh訪問這台主機就會出現沖突警告,需要手動刪除修改known_hsots裡面的內容。

有以下兩個解決方案:
1. 手動刪除修改known_hsots裡面的內容;
2. 修改配置文件“~/.ssh/config”,加上這兩行,重啟服務器。
StrictHostKeyChecking no
UserKnownHostsFile /dev/null

優缺點:
1. 需要每次手動刪除文件內容,一些自動化腳本的無法運行(在SSH登陸時失敗),但是安全性高;
2. SSH登陸時會忽略known_hsots的訪問,但是安全性低;

Copyright © Linux教程網 All Rights Reserved