【git】github多账号设置
github多账号设置
生成ssh:由于不同的 GitHub 不能使用同一个 SSH 公钥,所以要生成两个不同的 SSH 分别对应两个主账户和副账户。
1. 生成 SSH 的命令如下:
ssh-keygen -t rsa -f ~/.ssh/id_rsa_blog -C "blogemail@gmail.com"
ssh-keygen -t rsa -f ~/.ssh/id_rsa -C "mainemail@gmail.com"
-f 选项指定生成钥匙对的文件名。
正确操作后目录 .ssh/ 下应该是这样的:
[root@VM-16-4-centos ~]# ls .ssh/
id_rsa id_rsa_blog id_rsa_blog.pub id_rsa.pub
2. SSH 配置:编辑 ~/.ssh/config SSH 配置文件,没有该文件则新建。
# mainemail@gmail.com
Host github-main.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
# blogemail@gmail.com
Host github-blog.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_blog
3. 然后,以后使用 main 账户添加远程仓库需要这样添加:
git remote add origin git@github-main.com:username/demo.git
类似,使用 blog 账户时是这样:
git remote add origin git@github-blog.com:username/demo.git
而非原来的:
git remote add origin git@github.com:username/demo.git
4. 测试是否配置成功,部署相应的 SSH 公钥到 GitHub 后,尝试在相应的本地仓库 git push 几个文件测试。
参考资料

浙公网安备 33010602011771号