【问题标题】:Is there a way to avoid the default git user in the ssh config? [duplicate]有没有办法避免 ssh 配置中的默认 git 用户? [复制]
【发布时间】:2021-04-08 13:48:20
【问题描述】:

我在同一台计算机上有 2 个 github 帐户,我希望能够提供我希望进行身份验证的用户(即 ssh userA@githubssh userB@github)。这适用于以下 .ssh/config 文件:

Host github.com
  Hostname github.com
  PreferredAuthentications publickey
  IdentityFile .ssh\userA_key
  User userA
Host github.com
  Hostname github.com
  PreferredAuthentications publickey
  IdentityFile .ssh\userB_key
  User userB

但是,如果我使用 git 用户(即ssh git@github.com)进行身份验证。我收到一条成功通过身份验证的消息,其中包含首先出现在配置文件 (userA) 中的用户。有没有办法防止这种情况?我想提供 userA 或 userB,但无法以 git 用户身份进行身份验证。

【问题讨论】:

  • 您只能以git@github.com 身份进行身份验证。您是通过您提供的 ssh 密钥而非用户名来识别的。

标签: git github ssh


【解决方案1】:

如果您使用 GitHub,则需要始终使用 git 用户。 GitHub 和许多其他提供 Git 托管的地方一样,始终使用用户 git,然后根据提供的 SSH 密钥确定用户的身份。

所以如果你使用 userA 的 SSH 密钥和 git 用户,那么 GitHub 会认为你是 userA,如果你使用 userB 的 SSH 密钥和 git 用户,那么 GitHub 会认为你是 userB。无需通过用户名来识别自己。

在其他一些托管环境中,例如使用Gitolite或其他自托管环境时,git用户用于Git操作,对服务器的正常访问由其他用户授予。例如,如果我想推送 Git 数据,我会以用户 git 进行身份验证,但如果我想正常访问服务器,我可能会以 bk2204 身份进行身份验证。 GitHub 并非如此,它使用专用服务来终止 Git SSH 连接,但对于其他托管环境可能是正确的,这也是该模式流行的部分原因。

【讨论】:

    猜你喜欢
    • 2021-12-15
    • 1970-01-01
    • 2010-11-19
    • 1970-01-01
    • 2019-09-07
    • 1970-01-01
    • 2012-08-21
    • 2020-12-02
    • 2019-05-29
    相关资源
    最近更新 更多