从两个不同的 Git 帐户克隆/推送/拉取



所以我有一个个人Bitbuket帐户,我用它来克隆/推送/拉取没有问题。
我正在使用 Git-Bash,并使用 git config --global user.namegit config --global user.email

做了一个全局用户名和密码现在我在 Gitlab 上获得了一个具有不同电子邮件和密码的新帐户,并且我创建了一个新的 SSH 密钥id_rsa_gitlab并将该 SSH 密钥ssh-add ~/.ssh/id_rsa_gitlab添加到 gitlab.lan 帐户,并将该规则添加到配置文件中......

Host bitbucket.org
 IdentityFile ~/.ssh/id_rsa
Host gitlab
  HostName gitlab.lan
  User git
  IdentityFile ~/.ssh/id_rsa_gitlab

但是现在当我尝试从 Gitlab 存储库克隆时,我收到此错误......

ssh: connect to host gitlab.lan port 22: Connection timed out
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.


我在这里错过了什么?
我需要更改全局 user.name 和 user.password 还是什么?

您需要

仔细检查您的URL是否确实利用了您的~/.ssh/config条目。

如果应该是:

gitlab:project/repo.git

ssh -T gitlab应该打印一条欢迎消息。

添加了 SSH 密钥ssh-add ~/.ssh/id_rsa_gitlab并添加到gitlab.com帐户

为此,请确保您的主机名是 gitlab.com ,而不是gitlab.lanconfig文件中。
并确保已将公钥内容(~/.ssh/id_rsa_gitlab.pub)添加到 gitlab.com 用户ssh设置中。

我确认,在公司中,使用 ssh 的传出查询通常是......封锁!在这种情况下,使用 https 是更好的选择。

最新更新