安装了最新版本的 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
相关参考: