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

Pat*_*ick 4 ruby linux github symfony 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_methods: ["publickey"]
}
Run Code Online (Sandbox Code Playgroud)

部署时

bundle exec cap staging deploy --trace
Run Code Online (Sandbox Code Playgroud)

脚本连接正常,但失败了

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
Run Code Online (Sandbox Code Playgroud)

我不知道为什么forward_agent不工作?

我一直在尝试遵循本指南 - https://developer.github.com/guides/using-ssh-agent-forwarding/#testing-ssh-agent-forwarding

但是当我到达这个时

echo "$SSH_AUTH_SOCK"
Run Code Online (Sandbox Code Playgroud)

它打印一个空行.

此外,如果我在服务器上运行它,它说命令未找到

sshd_config
Run Code Online (Sandbox Code Playgroud)

wil*_*_wi 6

仔细检查运行Capistrano的用户是否已ssh-agent运行并已ssh-add编辑相关密钥.

以下是一些很好的指南:

https://developer.github.com/guides/using-ssh-agent-forwarding/

http://mah.everybody.org/docs/ssh