GitHub 多账户设置
生成 SSH
由于不同的 GitHub 不能使用同一个 SSH 公钥,所以要生成两个不同的 SSH 分别对应两个主账户和副账户。
Ubuntu 生成 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 文件
编辑 ~/.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然后,以后使用 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测试
部署相应的 SSH 公钥到 GitHub 后,尝试在相应的本地仓库 git push 几个文件测试。
文章作者 sulinehk
来源https://www.sulinehk.com/post/github-mult-account/
本文内容仅供个人学习/研究/参考使用,不构成任何决策建议或专业指导。分享/转载时请标明原文来源,同时请勿将内容用于商业售卖、虚假宣传等非学习用途哦~感谢您的理解与支持!