报错部分代码
remote: Invalid username or token. Password authentication is not supported for Git operations.
解决步骤
- 生成GitHub专用密钥
ssh-keygen -t ed25519 -C "你的GitHub邮箱" -f ~/.ssh/id_ed25519_github
- 查看并复制公钥
cat ~/.ssh/id_ed25519_github.pub
- 在GitHub上面保存公钥
- 测试连接
ssh -T git@github.com
其他错误
SSH 服务未启动或端口被屏蔽
Connection closed by...port 22
解决步骤
- 编辑
~/.ssh/config
文件(如果没有,可以创建一个)
nano ~/.ssh/config
- 添加以下内容
Host github.com
HostName ssh.github.com
User git
Port 443
SSH 密钥未正确加载、GitHub 没有正确添加公钥、或者配置不正确等
git@ssh.github.com: Permission denied (publickey)
解决步骤
- 先使用下面的命令查看 SSH 代理是否已加载你的私钥
ssh-add -l
如果返回:
The agent has no identities
,则使用下面的命令 ssh-add ~/.ssh/id_ed25519_github