Git SSH 密钥:github 和 gitlab 的两个不同帐户

JPG*_*JPG 5 git ssh-keys gitlab

有什么办法可以使用两个不同的邮箱地址通过SSH Key操作GitLabGitHub账户吗?

我有两个邮件 id,username@gmail.com并且username@xyz.in我想将一些项目推送到 gitlab 以及一些其他项目到 github,并且我想避免在每个推送命令中输入密码提示。是否可以?

gtu*_*rri 6

您可以尝试使用 ssh 而不是 https:将您的公共 ssh git 上传到服务器,并使用 ssh url。例如,对于 github,你不应该有一个像

https://github.com/<username>/<repo>.git
Run Code Online (Sandbox Code Playgroud)

但你应该有

git@github.com:<username>/<repo>.git
Run Code Online (Sandbox Code Playgroud)

——

现在,要使用不同的 ssh 密钥或用户名,您可以尝试将~/.ssh/config文件设置为类似

Host           gitlab.com
HostName       gitlab.com
IdentityFile   ~/.ssh/gitlab
User           username@gmail.com

Host           github.com
HostName       github.com
IdentityFile   ~/.ssh/github
User           username@xyz.in
Run Code Online (Sandbox Code Playgroud)

IdentityFile您的 ssh 私钥的路径在哪里