`

SSH下know_hosts的作用(转)

 
阅读更多
原文地址:http://blog.csdn.net/yasaken/article/details/7348441

在平时工作中,有时候需要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的访问,但是安全性低;
分享到:
评论

相关推荐

    puppet-known_hosts:用于管理用户和系统已知主机的人偶模块

    该模块将管理/etc/ssh/ssh_known_hosts和您为其配置的用户的~/.ssh/known_hosts 。 它将清除这些文件中的所有非托管条目。 这与sshkey资源不同,后者不清除条目,而仅管理系统范围内的已知主机。 设置 什么known_...

    SSH密钥认证登录.doc

    4. 如果需要,确保服务端的`~/.ssh/known_hosts`文件包含了所有需要信任的客户端主机的指纹信息,以避免每次连接时的确认提示。 在实际应用中,要注意文件的权限设置。例如,`.ssh`目录应具有`700`权限,`...

    Ansible报错解决方法...added 'IP' (ECDSA) to the list of known hosts

    总的来说,"Permanently added 'IP' (ECDSA) to the list of known hosts"这个错误通常不是一个严重的问题,它反映了SSH的安全机制在起作用。然而,根据你的安全策略和自动化需求,你可能需要采取不同的策略来处理这...

    Linux下实现免密码登录(超详细)

    1.Linux下生成密钥  ssh-keygen的命令手册,通过”man ssh-keygen“命令:  通过命令”ssh-keygen ... know_hosts : 已知的主机公钥清单  如果希望ssh公钥生效需满足至少下面两个条件:  1) .ssh目录的权限必须是

    Python paramiko模块使用解析(实现ssh)

    开发堡垒机之前,先来学习Python的...# 允许连接不在know_hosts文件中的主机 ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # 连接服务器 ssh.connect(hostname="10.0.0.200", port=22, username='r

    python实现ssh及sftp功能(实例代码)

    1.在Linux上我们通过scp命令实现主机间的文件传送,通过ssh实现远程登录 ,比如 我们经常使用的xshell远程登录工具,就是基础ssh协议实现window主机...# 允许连接不在know_hosts文件中的主机 ssh.set_missing_host_key_p

    Homelab-infra:Homelab管理基础结构(Packer Terraform Ansible)

    这是我的Homelab基础结构。...ansible-playbook -i hosts playbooks/add-ssh-keys.yml 用于创建由CA签名的客户端证书的剧本 ansible-playbook playbooks/generate-certs.yml 部署区域的剧本 ansible-playbook -

    hetzner-bootstrap:hetzner.de的installimagebootstrapping服务的接口

    hetzner-bootstrap hetzner-bootstrap允许您从hetzner.de引导已配置的EQ服务器 它能做什么: 当您在hetzner购买大量服务器时,通常会在首次使用前手动重新安装每个...将生成的服务器密钥添加到您的.know_hosts文件中

    hydra 7.2 win32

    NOTE: if you are cracking parallel hosts (-M option), this feature doesnt work, and is therefore disabled! NOTE: the hydra.restore file can NOT be copied to a different platform (e.g. from little ...

    计算机网络第六版答案

    After finding the vulnerability, the attacker needs to scan for hosts that are vulnerable. The target is basically to compromise a series of systems by exploiting that particular vulnerability. Any ...

Global site tag (gtag.js) - Google Analytics