首先需要设置git用户信息1
2git config --global user.name "yourname"
git config --global user.email "youremail"
一、对于单个SSH key
1、执行cd ~/.ssh命令,如果存在该目录,表明之前生成过SSH Key,利用ll命令即可以查看
1 | cd ~/.ssh |
2、若没有,则可以生成新的SSH key
1 | ssh-keygen -t rsa -C "username@example.com" |
3、在~/.ssh目录下有 id_rsa(私钥)和 id_rsa.pub(公钥)两个文件,其中id_rsa.pub文件里存放的即是公钥key
4、添加私钥
1 | ssh-add ~/.ssh/id_rsa |
5、登录到GitHub,点击右上方的头像,选择settings ,点击Add SSH key,把id_rsa.pub的内容复制到里面即可
二、对于一台电脑针对多个Github账户添加多个公钥:
1、生成多个SSH key
1 | ssh-keygen -t rsa -C "hbcdec@gmail.com” -f ~/.ssh/id1_rsa |
2、添加私钥
1 | ssh-add ~/.ssh/id1_rsa |
3、修改配置文件
1 | vim config |
1 | #personal |
4、添加不同公钥到对应GitHub账户
5、测试
1 | ssh -T git@personal |
如果提示1
Hi xxx You've successfully authenticated, but GitHub does not provide shell access.
说明连接成功。