Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby Capistrano 3部署无法连接到GitHub-权限被拒绝(公钥)_Ruby_Linux_Symfony_Github_Capistrano3 - Fatal编程技术网

Ruby Capistrano 3部署无法连接到GitHub-权限被拒绝(公钥)

Ruby Capistrano 3部署无法连接到GitHub-权限被拒绝(公钥),ruby,linux,symfony,github,capistrano3,Ruby,Linux,Symfony,Github,Capistrano3,我使用Capistrano v3和Capistrano/symfony gem设置了以下部署脚本。我正在使用Ubuntu 14.4部署到AWS EC2实例 我正在连接从AWS下载的.pem文件。我的deploy.rb中有以下内容 set :pty, true set :ssh_options, { user: 'ubuntu', keys: ['/Users/myuser/Sites/Myproject.pem'], forward_agent: true, auth_meth

我使用Capistrano v3和Capistrano/symfony gem设置了以下部署脚本。我正在使用Ubuntu 14.4部署到AWS EC2实例 我正在连接从AWS下载的.pem文件。我的deploy.rb中有以下内容

set :pty, true

set :ssh_options, {
  user: 'ubuntu',
  keys: ['/Users/myuser/Sites/Myproject.pem'],
  forward_agent: true,
  auth_methods: ["publickey"]
}
使用部署时

bundle exec cap staging deploy --trace
脚本连接良好,但在这方面失败

INFO [4fd1b02c] Running /usr/bin/env git ls-remote --heads git@github.com:MyName/Myproject.git as ubuntu@ec2-00-000-000-000.eu-west-1.compute.amazonaws.com
DEBUG [4fd1b02c] Command: ( SYMFONY_ENV=prod GIT_ASKPASS=/bin/echo GIT_SSH=/var/www/tmp/myproject/git-ssh.sh /usr/bin/env git ls-remote --heads git@github.com:MyName/Myproject.git )

DEBUG [4fd1b02c]    Permission denied (publickey).
DEBUG [4fd1b02c]    
DEBUG [4fd1b02c]    fatal: Could not read from remote repository.
DEBUG [4fd1b02c]    
DEBUG [4fd1b02c]    
DEBUG [4fd1b02c]    Please make sure you have the correct access rights
DEBUG [4fd1b02c]    
DEBUG [4fd1b02c]    and the repository exists.
DEBUG [4fd1b02c] 

cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as ubuntu@ec2-00-000-000-000.eu-west-1.compute.amazonaws.com: git exit status: 128
git stdout: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
git stderr: Nothing written
我不知道为什么转发代理不工作

我一直在努力遵循这个指南-

但当我谈到这件事时

echo "$SSH_AUTH_SOCK"
它打印一个空行

另外,如果我在服务器上运行此命令,它会显示找不到命令

sshd_config

再次检查运行Capistrano的用户是否运行了
ssh代理
,是否添加了相关密钥

以下是一些很好的指南:


解决我问题的办法是两件事。首先,我必须在脚本中转发我的id_rsa,如下所示:

set :ssh_options, {
  user: 'ubuntu',
  keys: ['~/.ssh/id_rsa'],
  forward_agent: true,
  auth_methods: ["publickey"]
}
我将id_rsa.pub密钥放在服务器上,这样我就可以使用与转发时相同的密钥通过ssh连接到服务器

我必须做的第二件事是使用设置/tmp上的权限

chmod 1777 /tmp

我在cap运行期间遇到过类似的问题“
$bundle exec cap test deploy

对于这个场景,我们需要使用ssh密钥对github帐户进行身份验证

导航到github->Settings->SSH和GPG密钥(部分)->添加“新SSH密钥”,复制您的公钥(
$SSH-keygen#generate-New-Key
)并粘贴密钥输入字段。添加密钥后,使用以下命令“
$ssh-Tgit@github.com
“检查身份验证。它将显示以下输出

Hi <xxxxxxxx>! You've successfully authenticated, but GitHub does not provide shell access.
你好!您已成功通过身份验证,但GitHub不提供shell访问。 现在它工作得很好

  • 添加下一个gems结束包
  • gem'capistrano',require:false
    gem“capistrano捆绑机”,要求:false
    gem“capistrano rails”,要求:false
    宝石“capistrano rvm”,要求:假
    宝石“capistrano sidekiq”,要求:false
    
  • $cap-T
  • 您可以看到所有命令的描述

  • 从变体环境中结束do命令
  • 如果检查生产

    $cap生产部署:选中

    如果分段


    $cap staging deploy:check

    谢谢,请问我该怎么做?相关的关键是什么?我搞不清楚我用ssh连接到EC2的.pem和连接到GitHub所需的密钥。我更新了答案。这里讨论的密钥是您的GitHub密钥。假设您使用的是Mac或Linux,它位于
    ~/.ssh/id\u dsa
    ~/.ssh/id\u rsa
    中。我已经这样做并运行了
    ssh-Tgit@github.com
    并收到了成功消息,但在部署时仍会收到公钥错误,好像它没有转发。当您使用ssh连接到服务器并运行
    echo“$ssh\u AUTH\u SOCK”
    时,它返回了什么吗?那么ssh密钥没有被转发。您应该能够浏览GitHub指南并使其正常工作。现在,我在部署期间收到了其他失败的消息,对此我提出了一个新问题-
    Hi <xxxxxxxx>! You've successfully authenticated, but GitHub does not provide shell access.