1、打开git命令行控制台,执行:
ssh-keygen -t rsa -C "123456@qq.com"
2、执行到:
Enter file in which to save the key (/c/Users/Lang/.ssh/id_rsa):
输入你想存放的目录,例如:/E/Project/gitTest/.ssh/id_rsa
再继续三次Enter后,去此目录:
ec /E/Project/gitTest/.ssh/
3、查看公钥:
cat ./id_rsa.pub
复制公钥粘贴到gitHub,SSH keys / Add new输入框,进行提交
4、拉取仓库:
git clone git@github.com:YourProject/test.git
发现有报错:
Cloning into 'VideoScreenshot'...
Warning: Permanently added the RSA host key for IP address '1xxxxxxx23' to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists
5、这是因为没有把专用密钥添加到ssh-agent的高速缓存中
于是执行添加命令:
ssh-add /E/Project/gitTest/.ssh/id_rsa
6、若执行ssh-add /E/Project/gitTest/.ssh/id_rsa 时出现以下错误:
Could not open a connection to your authentication agent
则先执行如下命令启动ssh代理:
ssh-agent bash