Linux的ssh的known_host檔案

來源:互聯網
上載者:User

標籤:衝突   dmi   message   change   off   oss   something   計算   缺點   

在平時工作中,有時候需要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的訪問,但是安全性低。

Linux的ssh的known_host檔案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.