Capistrano和GitHub Private Repo - 权限被拒绝(publickey) [英] Capistrano and GitHub Private Repo – Permission denied (publickey)

查看:216
本文介绍了Capistrano和GitHub Private Repo - 权限被拒绝(publickey)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承了一个Rails项目,托管在Linode上。

以前的开发人员使用BitBucket存储库以及Capistrano进行部署。

自从在GitHub上设置私有存储库后,我试图让Capistrano配方工作。我没有运气。我在配置过程中继续出现publickey错误。



以下是我采取的步骤 -


  1. 更新了Linode服务器上的Git remote(origin)URL以指向我的新存储库
  2. 更新了Capfile中的存储库引用,以引用我的新存储库
  3. li>
  4. 在Capfile中将 ssh_options [:forward_agent] 设置为true
  5. 生成一个SSH密钥local(id_rsa.pub)并将其添加到我在GitHub中的用户帐户中
  6. 执行 ssh-add 命令,以确保身份添加了auth代理

  7. Ran ssh -T git@github.com 确认ssh已在本地正确设置

  8. 登录到我的Linode服务器并运行 ssh -T git@github.com 以确保它也能正常工作

  9. ol>

    另外,为了防止forward_agent属性不起作用,我甚至尝试在Linode服务器上生成一个SSH密钥,并添加它到GitHub。

    毕竟,当我运行 cap deploy 时,出现以下错误:

    p>

     权限被拒绝(publickey)。 
    致命:远程终端意外挂断

    以下是我正在使用的配方 -

     需要bundler / capistrano

    服务器---- SERVER IP ---- ::web,:app,:db,primary:true

    set:application,blog
    set:user,deployer
    set:deploy_to,/ var / www / blog
    set:deploy_via,:remote_cache $ b $ set:use_sudo,false
    $ b $ set:scm,git$ b $ set:repository,git @ github.com: - MY USERNAME - / blog.git
    set:branch,master

    default_run_options [:pty] = true
    ssh_options [:forward_agent ] = true

    在deploy,deploy:cleanup之后#只保留最后5个版本

    命名空间:deploy do
    task:start do;结束
    任务:停止做;结束
    任务:重新启动,角色:: app,除了:{no_release:true} do
    运行touch#{deploy_to} /current/tmp/restart.txt
    end

    任务:setup_config,角色:: app do
    sudoln -nfs#{current_path} /config/apache.conf / etc / apache2 / sites-available / blog
    run mkdir -p#{shared_pa​​th} / config
    把File.read(config / database.example.yml),#{shared_pa​​th} /config/database.yml
    puts现在编辑#{shared_pa​​th}中的配置文件。
    结束
    在deploy:setup,deploy:setup_config之后

    任务:symlink_config,角色:: app do
    运行ln -nfs#{shared_pa​​th } /config/database.yml#{release_path} /config/database.yml
    runln -nfs#{shared_pa​​th} / public / avatars#{release_path} / public / avatars
    end $ deploy:finalize_update,deploy:symlink_config之后的b

    $ b desc确保本地git与远程同步。
    任务:check_revision,roles::web do
    除非`git rev-parse HEAD` ==`git rev-parse origin / master`
    putsWARNING:HEAD不一样origin / master
    puts运行`git push`来同步更改。
    退出
    结束
    结束
    在deploy,deploy:check_revision之前
    结束

    我似乎无法弄清楚我要出错的地方 - 任何帮助都将不胜感激。






    UPDATE



    我还确保将以下内容添加到本地〜/ .ssh / config文件中...

     主机mydomain.com 
    ForwardAgent是


    解决方案

    今天我找到了MAC的根本原因。我的ssh密钥没有添加到身份验证代理,因此密钥未被转发。解决方案是执行以下命令:

    blockquote
    ssh-add〜/ .ssh / id_dsa
    blockquote>

    (或者如果您使用rsa键,则使用ssh-add〜/ .ssh / id_rsa)

    I've inherited a Rails project, hosted on Linode.

    The previous developer was using a BitBucket repository, along with Capistrano for deployments.

    I've since setup a private repository on GitHub, and I'm trying to get the Capistrano recipe to work. I'm having no luck. I continue to get a publickey error during deployment.

    Here are the steps I've taken –

    1. Updated the Git remote (origin) URL on the Linode server to point to my new repository
    2. Updated the repository reference in the Capfile, to reference my new repository
    3. Ensured ssh_options[:forward_agent] was set to true in the Capfile
    4. Generated an SSH key locally (id_rsa.pub) and added it to my user account in GitHub
    5. Executed the ssh-add command, to ensure the identity was added for auth agent
    6. Ran ssh -T git@github.com to confirm ssh was properly setup locally
    7. Logged into my Linode server and ran ssh -T git@github.com to ensure it was working also

    Additionally, just in case the forward_agent property wasn't working, I even tried generating an SSH key on the Linode server, and adding it to GitHub as well. No luck.

    After all of this, when I run cap deploy, I get the following error:

    Permission denied (publickey).
    fatal: The remote end hung up unexpectedly    
    

    Below is the recipe I'm using –

    require "bundler/capistrano"
    
    server "----SERVER IP----", :web, :app, :db, primary: true
    
    set :application, "blog"
    set :user, "deployer"
    set :deploy_to, "/var/www/blog"
    set :deploy_via, :remote_cache
    set :use_sudo, false
    
    set :scm, "git"
    set :repository, "git@github.com:--MY USERNAME--/blog.git"
    set :branch, "master"
    
    default_run_options[:pty] = true
    ssh_options[:forward_agent] = true
    
    after "deploy", "deploy:cleanup" # keep only the last 5 releases
    
    namespace :deploy do
      task :start do; end
      task :stop do; end
      task :restart, roles: :app, except: {no_release: true} do
        run "touch #{deploy_to}/current/tmp/restart.txt"
      end
    
      task :setup_config, roles: :app do
        sudo "ln -nfs #{current_path}/config/apache.conf /etc/apache2/sites-available/blog"
        run "mkdir -p #{shared_path}/config"
        put File.read("config/database.example.yml"), "#{shared_path}/config/database.yml"
        puts "Now edit the config files in #{shared_path}."
      end
      after "deploy:setup", "deploy:setup_config"
    
      task :symlink_config, roles: :app do
        run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
        run "ln -nfs #{shared_path}/public/avatars #{release_path}/public/avatars"    
      end
      after "deploy:finalize_update", "deploy:symlink_config"
    
      desc "Make sure local git is in sync with remote."
      task :check_revision, roles: :web do
        unless `git rev-parse HEAD` == `git rev-parse origin/master`
          puts "WARNING: HEAD is not the same as origin/master"
          puts "Run `git push` to sync changes."
          exit
        end
      end
      before "deploy", "deploy:check_revision"
    end
    

    I can't seem to figure out where I'm going wrong – any help would be greatly appreciated.


    UPDATE

    I've also ensured the following was added to my local ~/.ssh/config file...

    Host mydomain.com
      ForwardAgent yes
    

    解决方案

    Today I found the root cause on MAC. My ssh key was not added to the authentication agent so the key was not forwarded. The solution was to execute the following command:

    ssh-add ~/.ssh/id_dsa

    (or ssh-add ~/.ssh/id_rsa if you use rsa key)

    这篇关于Capistrano和GitHub Private Repo - 权限被拒绝(publickey)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆