`
tinyhema
  • 浏览: 150371 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

git 使用ssh认证 提示Host key verification failed

 
阅读更多
问题描述

使用ssh认证模式,连接gitlab服务器,执行git pull报如下错误:

$ git pull
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@       WARNING: POSSIBLE DNS SPOOFING DETECTED!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The RSA host key for gitlab.alibaba-inc.com has changed,
and the key for the corresponding IP address 10.10.31.61
is unknown. This could either mean that
DNS SPOOFING is happening or the IP address for the host
and its host key have changed at the same time.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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 a host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx.
Please contact your system administrator.
Add correct host key in /Users/xx/.ssh/known_hosts to get rid of this message.
Offending RSA key in /Users/xx/.ssh/known_hosts:7
RSA host key for gitlab.xxx.com has changed and you have requested strict checking.
Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.


解决方案
  • 1. 删除~/.ssh/known_hosts 文件中包含"gitlab.xxx.com"这一行的记录

  • 2. 删除~/.ssh/known_hosts整个文件

  • 3. 修改open ssh配置文件,安全级别调低(不推荐,仅限内网等安全级别较高的环境,公网不要使用)

  • SSH对主机的public_key的检查等级是根据StrictHostKeyChecking变量来配置的。可以通过降低安全级别的方式,来减少这一类提示。

    修改方法:
    编辑~/.ssh/config(代表个人配置,或/etc/ssh/ssh_config,代表全局配置)
    添加以下行
    StrictHostKeyChecking no
    UserKnownHostsFile /dev/null  # 为了更简化,把known_hosts也省略掉了
    



    下面附上StrictHostKeyChecking配置项的说明。
    • StrictHostKeyChecking=no 
    • 最不安全的级别,当然也没有那么多烦人的提示了,相对安全的内网测试时建议使用。如果连接server的key在本地不存在,那么就自动添加到文件中(默认是known_hosts),并且给出一个警告。
    • StrictHostKeyChecking=ask 
    • 默认的级别,就是出现刚才的提示了。如果连接和key不匹配,给出提示,并拒绝登录。
    • StrictHostKeyChecking=yes 
    • 最安全的级别,如果连接与key不匹配,就拒绝连接,不会提示详细信息。



    分享到:
    评论

    相关推荐

    Global site tag (gtag.js) - Google Analytics