参考博客:
https://www.cnblogs.com/ailhc/p/6586465.html
https://www.cnblogs.com/cnlg123/p/7762889.html
https://www.cnblogs.com/xixihuang/p/5522424.html
大家方法都差不多,我这里主要是解决了Permission denied (publickey).和git clone的错误。
------------------------------------正文------------------------------------
所用到命令
git config --global user.name "guyongpu"
git config --global user.email "gyphust@qq.com"
rm -rf ~/.ssh/*
cd ~/.ssh
ssh-keygen -t rsa -C "gyphust@qq.com"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
cat id_rsa.pub
/*将id_rsa.pub的内容复制到github中*/
ssh -T git@github.com
ssh-add ~/.ssh/id_rsa
截图:
将id_rsa.pub的内容复制到github即可,此步骤很简单,不再赘述
常见的问题:
问题1:添加ssh key报错
yongpu@ubuntu:~/.ssh$ ssh -T git@github.com
The authenticity of host 'github.com (52.74.223.119)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,52.74.223.119' (RSA) to the list of known hosts.
sign_and_send_pubkey: signing failed: agent refused operation
Permission denied (publickey).
解决办法:输入
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
问题2: git clone报错
sign_and_send_pubkey: signing failed: agent refused operation
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
解决办法:
eval "$(ssh-agent -s)"
然后在git clone等操作,clone项目的时候选择ssh方式