【问题标题】:Github SSH config containing multiple ssh keys capistrano deployment fails saying Repository not found包含多个 ssh 密钥 capistrano 部署的 Github SSH 配置失败,提示找不到存储库
【发布时间】:2013-07-24 14:33:01
【问题描述】:

~/.ssh/config

# User_A
Host github.com-User_A
HostName github.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes

# User_B
Host github.com-User_B
HostName github.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_user_b
IdentitiesOnly yes

# http://serverfault.com/questions/400633/capistrano-deploying-to-different-servers-with-different-authentication-methods
Host example.com
IdentityFile ~/.ssh_keys/example_env.pem
ForwardAgent yes

在本地机器上:

  $ ssh -T git@github.com
  Hi User_B! You've successfully authenticated, but GitHub does not provide shell access.

在远程机器上

    ~$ ssh remote_user@example.com

    [remote_user@example ~]$ ssh -T git@github.com
    Hi User_A! You've successfully authenticated, but GitHub does not provide shell access.

注意:

  • ssh-add -l 显示所有提到的密钥
  • deploy.rb 包含:

     set :repository,  "git@User_B:<REPO_NAME>"
    
     ssh_options[:forward_agent] = true
    

我正在尝试使用 Capistrano 将我的应用程序部署到一个 Amazon EC2 实例,我已经使用 ssh-add 将 .pem 文件添加到我的本地计算机中,并且可以在 ssh-add 的输出中看到它-l。但是我在部署时遇到以下错误:

** [example.com :: err] ERROR: Repository not found.
** fatal: The remote end hung up unexpectedly

以下是我的 cap deploy 命令的完整输出:

$ cap bat deploy

  triggering load callbacks
* executing `bat'
  triggering start callbacks for `deploy'
* executing `multistage:ensure'
* executing `deploy'
* executing `deploy:update'
   ** transaction: start
* executing `deploy:update_code'
  updating the cached checkout on all servers
  executing locally: "git ls-remote git@User_B:<REPO_NAME> <BRANCH_NAME>"
  command finished in 6296ms
* executing "if [ -d /srv/<APP_NAME>/shared/cached-copy ]; then cd /srv/<APP_NAME>/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard df84fadff305e1729991caddde47f6802e424d57 && git clean -q -d -x -f; else git clone -q git@User_B:<REPO_NAME> /srv/<APP_NAME>/shared/cached-copy && cd /srv/<APP_NAME>/shared/cached-copy && git checkout -q -b deploy df84fadff305e1729991caddde47f6802e424d57; fi"
  servers: ["example.com"]
  [example.com] executing command
   ** [example.com :: err] ERROR: Repository not found.
   ** fatal: The remote end hung up unexpectedly
  command finished in 3811ms
  *** [deploy:update_code] rolling back
* executing "rm -rf /srv/<APP_NAME>/releases/20130723222237; true"
  servers: ["example.com"]
  [example.com] executing command
  command finished in 477ms
  failed: "sh -c 'if [ -d /srv/<APP_NAME>/shared/cached-copy ]; then cd /srv/<APP_NAME>/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard df84fadff305e1729991caddde47f6802e424d57 && git clean -q -d -x -f; else git clone -q git@User_B:<REPO_NAME> /srv/<APP_NAME>/shared/cached-copy && cd /srv/<APP_NAME>/shared/cached-copy && git checkout -q -b deploy df84fadff305e1729991caddde47f6802e424d57; fi'" on example.com

所以我猜这个错误是由于检测到多个 SSH 密钥之间产生的冲突引起的,即在本地计算机上 User_B(谁是存储库的成员)被用作默认值,但是在远程计算机上 User_A(谁没有访问权限存储库)被使用。

如果我的假设是正确的,有人可以帮我解决这个问题吗?代理转发时是否可以使用特定的用户配置?如果没有,那有什么办法解决这个问题?

谢谢。

【问题讨论】:

    标签: github ssh config ssh-keys


    【解决方案1】:

    好吧,看来 ~/.ssh/config 中列出的键的顺序很重要。

    最初是

        # User_A
        Host github.com-User_A
        HostName github.com
        User git
        PreferredAuthentications publickey
        IdentityFile ~/.ssh/id_rsa
        IdentitiesOnly yes
    
        # User_B
        Host github.com-User_B
        HostName github.com
        User git
        PreferredAuthentications publickey
        IdentityFile ~/.ssh/id_rsa_user_b
        IdentitiesOnly yes
    
        # http://serverfault.com/questions/400633/capistrano-deploying-to-different-servers-with-different-authentication-methods
        Host example.com
        IdentityFile ~/.ssh_keys/example_env.pem
        ForwardAgent yes
    

    后来我这样做了:

        # User_B
        Host github.com-User_B
        HostName github.com
        User git
        PreferredAuthentications publickey
        IdentityFile ~/.ssh/id_rsa_user_b
        IdentitiesOnly yes
    
        # User_A
        Host github.com-User_A
        HostName github.com
        User git
        PreferredAuthentications publickey
        IdentityFile ~/.ssh/id_rsa
        IdentitiesOnly yes
    
    
        # http://serverfault.com/questions/400633/capistrano-deploying-to-different-servers-with-different-authentication-methods
        Host example.com
        IdentityFile ~/.ssh_keys/example_env.pem
        ForwardAgent yes
    

    但是在这样做之后我没有重新启动机器,因此更改没有生效。

    今天早上我在发布上述问题后启动我的机器后发现它正在工作:

    在本地机器上:

      $ ssh -T git@github.com
      Hi User_B! You've successfully authenticated, but GitHub does not provide shell access.
    

    在远程机器上

      $ ssh -T git@github.com
      Hi User_B! You've successfully authenticated, but GitHub does not provide shell access.
    

    希望这可以帮助其他人,以防他遇到类似的问题。

    谢谢。

    【讨论】:

    • 你也可以输入 ssh -T github.com-User 来测试配置
    猜你喜欢
    • 2021-09-07
    • 2016-11-20
    • 1970-01-01
    • 1970-01-01
    • 2017-06-03
    • 1970-01-01
    • 1970-01-01
    • 2014-05-09
    • 2012-05-14
    相关资源
    最近更新 更多