1 2 3 4
| ## 生成ssh key
```shell ssh-keygen -t rsa -C “account-1@gmail.com”
|
假设账号account1生成的密钥保存在~/.ssh/id_rsa和~/.ssh/id_rsa.pub
1
| ssh-keygen -t rsa -C “account-2@gmail.com”
|
假设账号account2生成的密钥保存在~/.ssh/id_rsa_another和~/.ssh/id_rsa_another.pub
编辑config
~/.ssh/config
1 2 3 4 5 6 7 8 9
| Host account1 HostName github.com IdentityFile ~/.ssh/id_rsa port 22
Host account2 HostName github.com IdentityFile ~/.ssh/id_rsa_another port 22
|
测试
1 2
| ssh -T git@account1 ssh -T git@account2
|
用户名设置
1 2
| git config --global --unset user.name git config --global --unset user.mail
|
在仓库本地设置:
1 2
| git config --local user.name xxxx git config --local user.mail xxxx
|
远程连接
1 2 3 4
| # 原本的方式: git remote add origin https://github.com/<github usernmae>/<your repository name>.git # 现在使用config中的别名: git remote add origin git@account1:<github usernmae>/<your repository name>.git
|
生效ssh密钥
1
| ssh-add ~/.ssh/id_rsa_another
|
Link
https://blog.csdn.net/cheng5055251/article/details/127544657