更新 Git 版本后 gitlab 拉取代码异常:The authenticity of host xxx can’t be established

1,168次阅读
没有评论

共计 1013 个字符,预计需要花费 3 分钟才能阅读完成。

提醒:本文最后更新于2025-07-07 14:54,文中所关联的信息可能已发生改变,请知悉!

安装了最新版本的 Git 客户端(git version 2.34.1.windows.1)后,从 gitlab 拉取代码报如下错误(参考):

$ git pull -r -v
The authenticity of host ‘[gitlab.lzw.me]:10022 ([xxx.xxx.xxx.xxx]:10022)’ can’t be established.
ED25519 key fingerprint is SHA256:K+/XdcpPLPqHJsmSIsXHUMIrRVxivN9//YiYFp7VQeM.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added ‘[gitlab.lzw.me]:10022’ (ED25519) to the list of known hosts.
git@gitlab.lzw.me: Permission denied (publickey).
fatal: Could not read from remote repository.

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

根据错误提示信息分析得知,需要使用 ED25519 SSH 的 key。当前使用的是很久以前生成的 RSA SSH key。

解决方法如下:

Mac/Linux 下打开 terminal 终端,windows 下可以打开 Git Bash,执行命令生成 ED25519 SSH key。示例:

ssh-keygen -t ed25519 -C "email@lzw.me"

复制生成的 ED25519 SSH 公钥文件~/.ssh/id_ed25519.pub中的内容,然后在 gitlab SSH Keys 面板中添加它即可。

命令行方式复制 ~/.ssh/id_ed25519.pub 内容参考:

# macOS
pbcopy < ~/.ssh/id_ed25519.pub
# WSL / GNU/Linux (requires the xclip package):
xclip -sel clip < ~/.ssh/id_ed25519.pub
# Git Bash on Windows:
cat ~/.ssh/id_ed25519.pub | clip

相关参考:

正文完
 0
任侠
版权声明:本站原创文章,由 任侠 于2021-12-15发表,共计1013字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)
验证码