首页 文章

Capistrano和几个SSH密钥

提问于
浏览
15

我需要Capistrano使用2个不同的SSH密钥 . 一个用于git存储库,一个用于服务器部署到 .

无论我在.ssh文件夹中重命名为id_rsa的哪个键都有效 . 另一个没有 . 如果我将git键重命名为id_rsa,Capistrano可以连接到git存储库,但是无法在服务器上进行身份验证以进行部署 . 如果我称之为其他东西,它将无法连接到git repo . 我知道其他密钥有效,因为我可以执行ssh -i~ / .ssh / otherKey.pem并且它将成功连接到服务器 .

这就是我在deploy.rb Capistrano文件中的内容 .

ssh_options[:keys] = [
        File.join(ENV["HOME"], ".ssh", "id_rsa"),
        File.join(ENV["HOME"], ".ssh", "deploy")
    ]

ssh_options[:forward_agent] = true

我如何告诉Capistrano使用钥匙?它似乎只使用名为id_rsa的那个 .

编辑:

这是Capistrano的输出,错误信息如下:

$ cap yii deploy
  * executing `yii'
Yii
  * executing `deploy'
  * executing `deploy:update'
 ** transaction: start
  * executing `deploy:update_code'
    executing locally: "git ls-remote git@project.beanstalkapp.com:/projectyii.git HEAD"
  * executing "git clone -q git@project.beanstalkapp.com:/projectyii.git /var/www/projectyii-trunk/releases/20110824174629 && cd /var/www/projectyii-trunk/releases/20110824174629 && git checkout -q -b deploy 5e14521285ca04a605353e97bdf31c3a2889dbfb && (echo 5e14521285ca04a605353e97bdf31c3a2889dbfb > /var/www/projectyii-trunk/releases/20110824174629/REVISION)"
    servers: ["yii.project.com"]
    [yii.project.com] executing command
 ** [yii.project.com :: err] Error reading response length from authentication socket.
 ** [yii.project.com :: err] Permission denied (publickey,keyboard-interactive).
 ** [yii.project.com :: err] fatal: The remote end hung up unexpectedly
    command finished
*** [deploy:update_code] rolling back
  * executing "rm -rf /var/www/projectyii-trunk/releases/20110824174629; true"
    servers: ["yii.project.com"]
    [yii.project.com] executing command
    command finished
failed: "sh -c \"git clone -q git@project.beanstalkapp.com:/projectyii.git /var/www/projectyii-trunk/releases/20110824174629 && cd /var/www/projectyii-trunk/releases/20110824174629 && git checkout -q -b deploy 5e14521285ca04a605353e97bdf31c3a2889dbfb && (echo 5e14521285ca04a605353e97bdf31c3a2889dbfb > /var/www/projectyii-trunk/releases/20110824174629/REVISION)\"" on yii.project.com

编辑:

另一件事:它完全可以从我的本地机器上运行,而不是在部署服务器上 - 具有完全相同的配置文件!似乎Capistrano在我的本地机器上使用了正确的密钥,但在部署机器上却没有 .

4 回答

  • 0

    免责声明:我对Capistrano一无所知 .

    如果它只是执行正常的 ssh 调用(或调用 git 来执行此操作),则可以在每个主机(或每个主机别名)的基础上配置在 ~/.ssh/config 中使用的正确密钥 .

    例如,我在 ~/.ssh/config 文件中有这些行:

    # Git bei Github
    Host github.com
    User git
    IdentityFile ~/.ssh/svn_id_rsa
    
    #  Andere Mathe-Hosts
    Host *.math.hu-berlin.de
    User ebermann
    IdentityFile ~/.ssh/id_rsa
    ControlMaster auto
    
  • 10

    我在deploy.rb中有这一行:

    ssh_options[:keys] = %w(/Users/victor.pudeyev/ec2/MBP-2.pem)
    

    这表明密钥文件名是空格分隔的,例如

    ssh_options[:keys] = %w(/Users/victor.pudeyev/ec2/MBP-1.pem /Users/victor.pudeyev/ec2/MBP-2.pem)
    
  • 21

    我有这个问题,并在capfile中设置了ssh转发 . 删除它,允许目标框使用自己的密钥

  • 0

    派对有点晚了,但有一个选择是使用一点ruby glue来检测要使用的文件:

    ['~/.ssh/onekey.pem','~/.ssh/id_rsa'].each do |name|
      if File.exists?(File.expand_path(name))
        ssh_options[:keys] ||= name
      end
    end
    

相关问题