我有两个Github账号,在配置sshkey的时候是会提示Key is already in use
。因为github无法将相同的sshkey配置到不同的账号下,那么就要考虑同一台机器如何配置两个sshkey了。
生成第二个sshkey
因为之前已经存在~/.ssh/id_rsa
文件,所以这次生成的时候我们指定输出的文件名为id_rsa2
1
| ssh-keygen -t rsa -C "example@example.com" -f ~/.ssh/id_rsa2
|
创建config配置文件
在~/.ssh/
目录下创建config配置文件,内容如下,里面有详细的解释。
1 2 3 4 5 6 7 8 9 10 11
| # 原有的配置 Host github.com HostName github.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa
# 第二个配置 Host github_2.com HostName github.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa2 # 这里指定下所使用的公钥文件名,就是我们上一步新生成的那个。
|
使用第二个sshkey配置
假如我们的仓库地址为:git@github.com:name/project.git
,那么按照上面config
文件中Host
的配置,需要将仓库地址修改为:git@github_2.com:name/project.git
,修改git沧湖远程url的命令如下:
1
| git remote set-url origin git@github_2.com:name/project.git
|