【问题标题】:Clone / Push / Pull from two different Git accounts从两个不同的 Git 帐户克隆/推送/拉取
【发布时间】:2017-10-31 14:04:03
【问题描述】:

所以我有一个个人 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 还是什么?

【问题讨论】:

  • gitlab 是否在 22 端口运行?如果你在控制台上运行 ssh gitlab.lan 会发生什么?
  • @Ruby:你为什么不改变只是改变存储库的 user.name 和 user.email(不是全局的)并使用相同的 SSH 密钥?
  • @Flurin: 22端口是不是ssh端口?
  • 端口 22 通常是 SSH 端口,但大多数本地 git 包会监听其他东西 - 这样服务器管理员仍然可以使用端口 22 进行常规访问。
  • @Flurin 它打印ssh: connect to host gitlab.lan port 22: Connection timed out

标签: git ssh bitbucket gitlab git-bash


【解决方案1】:

您需要仔细检查您的网址是否利用了您的 ~/.ssh/config 条目。

如果应该是:

gitlab:project/repo.git

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

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

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

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

【讨论】:

  • 没用,主机是gitlab.lan 不是gitlab.com,当我做ssh -T gitlab 时它打印ssh: connect to host gitlab.lan port 22: Connection timed out
  • 那你需要整理一下服务器端的SSH情况,gitlab.lan。它显然没有在听。
  • 顺便说一句,我可以通过http 克隆存储库就好了,问题可能出在我使用的代理设置上吗?虽然我可以在 bitbucket.org 上使用 SSH 就好了。
  • @Ruby 代理用于 https,与 SSH 无关。 Bitbucket ssh clone 意味着您的防火墙不会阻止 SSH 连接。同样,问题出在服务器端“gitlab.lan”(无论指向哪里):它的 ssh 守护进程似乎没有激活。
  • 我想我在这个链接上发现了同样的问题......https://about.gitlab.com/2016/02/18/gitlab-dot-com-now-supports-an-alternate-git-plus-ssh-port/ 但是,它是针对gitlab.com 的,我用gitlab.lan 尝试过,但没有用。
猜你喜欢
  • 2018-05-13
  • 1970-01-01
  • 2017-05-12
  • 2012-09-29
  • 2012-02-20
  • 2019-04-10
  • 1970-01-01
  • 2020-05-23
  • 2011-05-11
相关资源
最近更新 更多