解决办公IP变化后git无法推送远程仓库的问题

解决办公IP变化后git无法推送远程仓库的问题

最近公司乔迁新址,在提交代码时遇到了无法git push的问题。报错如下:

1
2
3
4
5
The RSA host key for github.com has changed,
and the key for the corresponding IP address 42.243.156.48
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.

经检查,ssh密钥对是没有问题的,问题出在了known_hosts文件,办公ip变化了,而known_hosts中保留的是原来的ip,导致不识别当前ip而验证失败。

解决方法也很简单,首先找到.ssh目录,我的是

1
C:\Users\Jiang.Wenbin\.ssh

我们删除掉known_hosts文件,然后打开git bash,视个人情况选择性输入如下命令:

1
2
3
4
5
6
// 连接github
ssh -T git@github.com
// 连接gitee
ssh -T git@gitee.com
// 连接coding.net
ssh -T git@git.coding.net

在弹出询问后输入yes即可。

这里在连接github时比较特殊,遇到了一个报错

1
git@github.com: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).

其实是我开启了网络代理或者fanqiang工具引起的,关闭后正常了。

再次git push代码就没问题了。


首发链接

公众号-前端司南

You forgot to set the qrcode for Alipay. Please set it in _config.yml.
You forgot to set the qrcode for Wechat. Please set it in _config.yml.
You forgot to set the business and currency_code for Paypal. Please set it in _config.yml.
You forgot to set the url Patreon. Please set it in _config.yml.
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×