记录本地与github连接报错问题

发布于:2024-08-01 ⋅ 阅读:(127) ⋅ 点赞:(0)

一、现状

本地有一个新仓库并有代码;github上新建一个仓库;

二、诉求

想把本地仓库的代码推送到远程新仓库内;

三、问题现状和解决办法

问题1:host key in xx to get rid of this message

# 关联远程分支
git remote add origin git@github.com:xxx/xxx.git

# 推送远程分支
git pull origin master

报错:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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
SHA256:uNiVztksCsDhcc0u9e8BujQXVUpKZIDTMczCvj3tD2s.
Please contact your system administrator.
Add correct host key in /Users/xxx/.ssh/known_hosts to get rid of this message.
Offending RSA key in /Users/xxx/.ssh/known_hosts:4
Host key for github.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.

看错误提示,说host key不正确;因此需要生成正确的key并重新配置。

# 依次执行命令 更新key
ssh-keygen -R github.com
curl -L https://api.github.com/meta | jq -r '.ssh_keys | .[]' | sed -e 's/^/github.com /' >> ~/.ssh/known_hosts

把id_rsa.pub文件内的key添加到github账户内的sshkey内。

# 查看新的key 复制并黏贴至github账户的sshkey内
cat /Users/xxx/.ssh/id_rsa.pub

再通过命令验证本地与远程是否可以通信:

ssh -T git@github.com

# 出现以下信息表明链接成功:
Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.

再推送至远程分支:

git branch -M master
git push -u origin master

四、参考资料

https://github.blog/news-insights/company-news/we-updated-our-rsa-ssh-host-key/
https://stackoverflow.com/questions/2643502/git-how-to-solve-permission-denied-publickey-error-when-using-git


网站公告

今日签到

点亮在社区的每一天
去签到