解决github多个帐号提交不同仓库
解决github多个帐号提交不同仓库
- 经常遇到本地机器服务于多个github帐号/gitlab/codeup ,所以这里解决的就是这种不能提交的情况
准备
- 2个github帐号 如: account_one , account_two
- 本地用ssh在 【~/.ssh】 目录下生成2个帐号的公钥,分别复制两个账号 xxx.pub
ssh-keygen -t rsa -C "account_one@github.com" -f ~/.ssh/id_rsa.account_one ssh-keygen -t rsa -C "account_two@github.com" -f ~/.ssh/id_rsa.account_two
- 分别在两个github帐号中添加刚刚复制的公钥到两个仓库配置中,分别保存。
- 重点:这一步完成后就是配置本地:【~/ssh/config】文件
# github account_one Host github # 这里用一个别名github 来代替github.com 域名 HostName github.com User account_one PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa.account_one # github account_two Host github2 # 这里用一个别名github2 来代替github.com 域名 HostName github.com User account_two PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa.account_two
- 完成之后保存,然后测试是否成功
- 以上是我个人情况, 用例可以是
- ssh -T github
- ssh -T github2
解决github多个帐号提交不同仓库
http://blog.darrenzzy.cn/2022/10/29/解决github多个帐号提交不同仓库/