从Bitbucket部署到Digital Ocean - 权限被拒绝(publickey)错误

时间:2014-08-11 13:58:10

标签: git ruby-on-rails-4 capistrano bitbucket digital-ocean

我正在尝试将我的Rails应用程序从Bitbucket部署到Digital Ocean。我使用Git作为我的版本控制系统,我做了以下几点:

  1. 抓住我的电脑ssh键pbcopy < ~/.ssh/id_rsa.pub
  2. 将我的计算机ssh密钥添加到Digital Ocean(https://cloud.digitalocean.com/ssh_keys
  3. 将我的计算机ssh密钥添加到Bitbucket repo作为部署密钥(https://bitbucket.org/<account name>/<project admin/deploy-keys
  4. 但是当我运行cap deploy时会出现此错误

        servers: [<server ip>]
        [<server ip>] executing command
     ** [<server ip> :: out] Permission denied (publickey).
     ** [<server ip> :: out]
     ** [<server ip> :: out] fatal: Could not read from remote repository.
     ** [<server ip> :: out]
     ** [<server ip> :: out]
     ** [<server ip> :: out] Please make sure you have the correct access rights
     ** [<server ip> :: out]
     ** [<server ip> :: out] and the repository exists.
     ** [<server ip> :: out]
    

    这是我的deploy.rb文件

    set :scm, "git"
    set :repository, "git@bitbucket.org:<user name>/<project name>.git"
    set :branch, "master"
    

    如果我clone回到我当地的回购,它运作正常。我浏览了Bitbucket文档,但仍然无法弄清楚缺少什么。

    我对Bitbucket的ssh工作:

    ssh -T git@bitbucket.org
    authenticated via a deploy key.
    
    
    You can use git or hg to connect to Bitbucket. Shell access is disabled.
    
    This deploy key has read access to the following repositories:
    
    <repor name>
    

    发现这个SO question但没有任何运气。

2 个答案:

答案 0 :(得分:8)

好的,我找到了解决方案,我会在这里添加它,以便有人可能会觉得它很有用。

我修复了我在Digital Ocean中创建SSH密钥并将其添加到Bitbucket的问题。

以下是步骤

  • 在Digital Ocean中创建SSH密钥
  • 将该SSH密钥添加为数字海洋SSH密钥
  • 将相同的密钥添加到Bitbucket部署密钥 (https://bitbucket.org/<user>/<project>/admin/deploy-keys

答案 1 :(得分:0)

如果要将其他SSH密钥添加到已经具有某些密钥的Droplet中,则需要通过SSH启用密码身份验证才能完成此操作。通过控制面板添加SSH密钥只能在创建过程中添加到Droplet中。

如果您无法使用现有的SSH密钥访问计算机,则需要使用Web控制台对Droplet执行以下步骤。要启用密码验证,请按照以下步骤操作。

使用您喜欢的文本编辑器编辑此配置文件。

/ etc / ssh / sshd_config

找到显示“ PasswordAuthentication no”的行,并将其更改为“ PasswordAuthentication yes”,然后保存并退出编辑器。

重新回到命令提示符后,运行以下命令以允许进行新的SSH更改。

/etc/init.d/ssh重新启动

一旦SSH重新启动,您可以尝试将SSH连接到您的Droplet。如果遇到权限被拒绝错误,则可能需要使用“ passwd”命令来更新密码。

当您通过计算机上的SSH成功​​登录服务器后,建议您按照以下文章中的步骤操作,以获取为此Droplet配置的新SSH密钥。

https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2

我希望这些信息对您有所帮助!如果您有任何疑问或在过程中遇到任何问题,请告诉我们!