从linode连接到github,Capistrano部署允许拒绝公钥

时间:2014-02-12 09:33:40

标签: ruby-on-rails ruby git github ssh

这是我第一次使用linode并将Rails应用程序上传到VPS,所以我可能会跳过一些明显的东西。

我遵循了两个教程 Ryan Bates video to deploying to a vpsDavid's answer on Stackoverflow

我想在Linode上部署我的rails应用程序(Ubuntu 13.10)

当我执行命令bundle exec cap deploy:update

由于公钥

,我得到了Linode无法连接到github的错误
user:my-app User$ bundle exec cap deploy:update
  * 2014-02-12 17:19:46 executing `deploy:update'
 ** transaction: start
  * 2014-02-12 17:19:46 executing `deploy:update_code'
    updating the cached checkout on all servers
    executing locally: "git ls-remote git@github.com:user/my-app.git master"
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
*** [deploy:update_code] rolling back
  * executing "rm -rf /home/user/apps/my-app/releases/20140212091953; true"
    servers: ["XXX.XXX.XX.XX"]
    [XXX.XXX.XX.XX] executing command
    command finished in 4607ms
Command git ls-remote git@github.com:user/my-app.git master returned status code pid 1529 exit 128

在我的本地计算机上,我可以在Github上提交并推送我的应用程序,我在本地计算机上安装了RSA密钥。它只是要求我每次推送我的应用程序时都使用我的用户名和密码登录。

在shell中的linode上,我可以使用ssh -vT git@github.com连接到github。我在linode服务器上有RSA密钥,我使用ssh-add添加了ssh-agent

我的deploy.rb

set :application, "my-app"
set :user, "user"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false
set :keep_releases, 3
default_run_options[:pty] = true
set :scm, :git
set :repository, "git@github.com:user/#{application}.git"
set :ssh_options, { :forward_agent => true }
# ssh_options[:forward_agent] = true
set :branch, "master"

我有点不知所措。

编辑:我有一个私人存储库

2 个答案:

答案 0 :(得分:5)

我刚从Linux迁移到Mac OSx。因此,我已将整个.ssh文件夹从linux导入到mac。虽然从Linux迁移到Linux但它有效,但为了使它在Mac上运行,我还要运行:

ssh-add

这就是整个修复;)有关详细信息,请参阅http://peteoliveira.com/deploying-with-capistrano-3-failing-permission-denied-publickey/

答案 1 :(得分:3)

所以我找到了这个github连接的解决方案。我实际上在捆绑安装失败的部署中遇到了另一个问题。无论如何,这是我学到的东西,我希望它能帮助别人。

您需要了解的内容:

  1. 当您希望推动您的公共或私人Github时,使用Capistrano 存储库到你的VPS服务器,你需要确保你的 服务器和您的计算机通过Github进行SSH访问。
  2. 即使你可以git push origin master,也不代表你有SSH 访问Github。以下是您排除故障的方式:
  3. A)确保您可以从计算机进行SSH访问

    1. 确保您的计算机上安装了Git Set up Git tutorial

    2. 确保您的本地计算机上有SSH密钥(使用Linux 或Mac)

      cd ~/.ssh然后 ls -a

      并查找文件id_rsaid_rsa.pub

    3. 如果您没有这些rsa个文件,请按照本教程进行操作 Generating SSH keys

    4. 复制SSH密钥

      pbcopy < ~/.ssh/id_rsa.pub # Copies the contents of the id_rsa.pub file to your clipboard

    5. 使用您的浏览器登录http://www.github.com并转到 your_username - &gt;编辑个人资料 - &gt;设置 - &gt; ssh键 https://github.com/settings/ssh。单击“添加键”按钮,添加标识计算机的名称并粘贴先前复制的键代码。

    6. 确保您已启用SSH代理。在终端类型

      ssh-add #enter a passphrase if you want to (recommended)

    7. 测试您是否可以使用Github进行SSH

      ssh git@github.com

    8. 第一次可能会要求您接受连接。 您应该得到以下回复

      PTY allocation request failed on channel 0
      Hi username! You've successfully authenticated, but GitHub does not provide shell access.
      Connection to github.com closed.
      

      您还可以通过运行

      确保正确找到您的id_rsa
      ssh -vT git@github.com
      # make sure that this line is not -1 (it means it couldn't find the file)
      => debug1: identity file /Users/YOUR_USERNAME/.ssh/id_rsa type 1
      

      现在你不应该permission denied (Public Key)

      B)确保您可以从服务器进行SSH访问

      1. 如果您未在服务器或ssh root@your_server_ip_address上设置用户,请运行ssh username@your_server_ip_address。然后,您将进入服务器shell,并且希望为计算机重复相同的过程。
      2. 注意:服务器SSH密钥与您的计算机不同。这意味着在Github上你需要添加2个SSH密钥,一个用于你的计算机,一个用于你的服务器。这就是为什么你需要在两台机器上重复这个过程。另外,为了简单起见,请不要尝试在每台计算机上安装多个SSH密钥。

        注2:在生成SSH密钥后的服务器中,要复制它,请运行命令cat ~/.ssh/id_rsa.pub

        一旦您的计算机和服务器都被Github接受,那么您可以使用capistrano和您的Github存储库更新您的rails应用程序。耶!