我有两个不同的账户。
帐户1 GitHub githubaccount@email.com
账户2 GitLab gitlubaccount@email.com
在我的.ssh文件夹中,我有一个来自GitHub帐户的SSH密钥。在配置文件中
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_edxxxxx在我的git配置中--全局user.mail和名称中,我有GitLab帐户信息。
我的问题是,如何在不同的项目中使用两个帐户及其各自的SSH密钥?有可能吗?
发布于 2022-05-16 18:08:49
我建议生成一个SSH密钥,并将它添加到GitLab和GitHub帐户中。你为每个本地回购设定的电子邮件并不重要。它们仅用于设置提交,与远程服务的身份验证无关。
发布于 2022-05-17 06:45:49
在我的
git config --global user.mail和name中,我有GitLab帐户信息。
这与身份验证无关:您可以使用xxx和xxx@yyy.com,这将是相同的。
如何为不同的项目使用两个帐户及其各自的SSH密钥?
这意味着两个关键:
user1
ssh-keygen -t ed25519 -P "" -f ~/.ssh/gh2:~/.ssh/id_edxxxxx:它的公钥应该注册到user2.然后,添加一个~/..ssh/config文件
Host gh1
User git
Port 22
Hostname github.com
IdentityFile ~/.ssh/id_ed25519
TCPKeepAlive yes
IdentitiesOnly yes
Host gh2
User git
Port 22
Hostname github.com
IdentityFile ~/.ssh/gh2
TCPKeepAlive yes
IdentitiesOnly yes将远程URL替换为:
cd /path/to/project1/local/clone
git remote set-url origin gh1:User1/project1
cd /path/to/project2/local/clone
git remote set-url origin gh2:User2/project2这样,“两个帐户都有各自的SSH密钥用于不同的项目”。
https://stackoverflow.com/questions/72263723
复制相似问题