ssh agent and ssh add for git Permission denied

git 使用 ssh

设置git全局信息

git config --global user.name "study"
git config --global user.email "study@outlook.com"

创建RSA证书

ssh-keygen -C "study@outlook.com"

添加 证书.pub 到 github 的 settings

测试SSH是否已可用

ssh -T git@github.com

若出现 *@github.com: Permission denied (publickey).

原因是 ssh 找不到密钥文件

可以用

ssh-add ~/.ssh/file.rsa

若出现 Could not open a connection to your authentication agent.

输入以下命令

ssh-agent bash

 最后测试一下

ssh -T git@github.com

 更改 git 仓库 url 设置

git remote -v
git remote remote origin
git remote add origin git@github.com:yourgit/yourproject.git

 最后,如果你做了上述修改,push 的时候,可能需要这个

git branch --set-upstream-to=origin/master

master 是对应的远程分支名称

原文地址:https://www.cnblogs.com/bushuosx/p/10965518.html