【问题标题】:How to set ssh config for 2 different gitlab accounts?如何为 2 个不同的 gitlab 帐户设置 ssh 配置?
【发布时间】:2021-11-10 17:27:13
【问题描述】:

我正在 gitlab 中为 2 个不同的帐户设置我的 ssh 配置。

Host gitlab.com-roulette
    HostName gitlab.com
    User norayr.ghukasian
    IdentityFile /home/norayr_ghukasyan/.ssh/id_ed25519_roulette

Host gitlab.com-devlix
    HostName gitlab.com
    User norayr.ghukasyan
    IdentityFile /home/norayr_ghukasyan/.ssh/id_ed25519_devlix

我收到Permission denied 错误。 对我来说奇怪的是第一个工作正常,因此我认为我的配置中有一些我不知道的小问题。我猜当用户或服务器尝试连接时,ssh 会自动将第一个配置与匹配的HostName 匹配。 如何正确设置它以适用于两个帐户?

附: Users 是不同的 - norayr.ghukasian 和 norayr.ghukasyan。

【问题讨论】:

标签: linux ubuntu ssh gitlab


【解决方案1】:

在Use difference accounts on a single GitLab instance 之后,您可以像这样设置您的配置:

Host norayr.ghukasian.gitlab.com
  Hostname gitlab.com
  PreferredAuthentications publickey
  User git
  IdentityFile /home/norayr_ghukasyan/.ssh/id_ed25519_roulette

Host norayr.ghukasyan.gitlab.com
  Hostname gitlab.com
  PreferredAuthentications publickey
  User git
  IdentityFile /home/norayr_ghukasyan/.ssh/id_ed25519_devlix

然后以norayr.ghukasian用户的身份克隆一个repo:

git clone git@norayr.ghukasian.gitlab.com:gitlab-org/gitlab.git

使用用户名作为别名并不是绝对必要的。如果您愿意,可以使用不同的别名并将其设置在 ssh 配置的 Host 部分。

要点:

  1. 您唯一需要告诉 GitLab 您是谁就是IdentityFile。
  2. 您可以通过您在 ssh 配置中配置的主机的别名来指示 git/ssh 使用特定的身份文件。

【讨论】:

  • 好的,成功了,非常感谢。但我一无所获。我已根据 gitlab 文档更新了我的远程 url 以包含主机别名。它是如何工作的 ? Host alias 和 git remote url 有什么关系?
  • 通过 Host 行上的 ssh 配置。当 ssh 去解析远程时,ssh 配置告诉它真正的主机名是gitlab.com(并使用该主机的其他关联设置)。希望能帮助@NorayrGhukasyan
猜你喜欢
  • 2012-04-25
  • 2015-06-28
  • 2015-07-30
  • 2016-04-27
  • 1970-01-01
  • 2011-03-14
  • 2022-09-23
相关资源
最近更新 更多