多账号配置GIT

Posted by PaysonChen on October 18, 2021

1、常规多账号

不同host的代码仓库之间的多账号SSH配置,网上的资料很多,这里简单找一个 配置多个SSH

2、多个Github账号

由于申请了多个域名,配置同一个github账号下的gitpage出现了异常,我想大概也是因为CNAME或者其他原因。尝试重新申请一个github账号分开管理也行。

之前账号github是用ssh配置的,新账号也尝试用ssh配置,

重新生成新的ssk-key,也配置了config文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# github2
Host a.github.com
Port 22
User a
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_github_a

# github 
Host b.github.com
Port 22
User b
HostName github.com
PreferredAuthentications publickea
IdentityFile ~/.ssh/id_rsa_github_b

clone b仓库的代码,提交代码时提示

1
2
ERROR: Permission to B/payson.github.io.git denied to A.
fatal: Could not read from remote repository.

就是提交时默认账号是A

如果改成B呢,公钥私钥没问题,config也配了,

最后查找资料发现,需要改Host

将仓库B的远程Host,加上config配置的 b.github.com

1
origin:git@b.github.com:b/payson.github.io.git

使Host与config的Host对应