步骤如下:
-
生成第二个账号密钥,要与原默认密钥id_rsa区分开,执行如下命令:
ssh-keygen -t rsa -C "你的第二个账号" -f ~/.ssh/id_rsa_new
-
把新生成的公钥id_rsa_new.pub添加到你的账号里
-
把新生成的key添加到ssh-agent上
先执行
ssh-agent bash
然后执行
ssh-add ~/.ssh/id_ras_new
-
配置ssh config
vi ~/.ssh/config
添加以下内容后保存即可
Host github.com HostName github.com IdentityFile ~/.ssh/id_rsa # 同一个域名使用不同账号 Host github_test HostName github.com IdentityFile ~/.ssh/id_rsa_test # 不同域名 Host git_hub HostName github.com IdentityFile ~/.ssh/id_rsa_new
-
当存在同一个域名,需要使用不同的账号时,就可以使用别名来明确需要用哪个账号进行操作,例如
将本地仓库绑定到远端
git remote add origin git@github_test:abcd/test.git
网友评论