我有以下部署脚本与Capistrano v3和capistrano / symfony创业板。 我正在使用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
我不知道为什么forward_agent不工作?
我一直在试图遵循本指南 – https://developer.github.com/guides/using-ssh-agent-forwarding/#testing-ssh-agent-forwarding
但是当我得到这个
echo "$SSH_AUTH_SOCK"
它打印一个空行。
另外如果我在服务器上运行它说没有find命令
sshd_config
仔细检查运行Capistrano的用户是否正在运行ssh-agent
,并且已经ssh-add
了相关的密钥。
这里有一些很好的指南:
https://developer.github.com/guides/using-ssh-agent-forwarding/
解决我的问题是两件事。 首先,我必须在脚本中转发我的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
我在运行“ $ bundle exec cap test deploy
”时遇到了类似的问题
Error : git stdout: Nothing written git stderr: Warning: Permanently added the RSA host key for IP address 'xxxxxxxxx' to the list of known hosts. Permission denied (publickey). fatal: Could not read from remote repository.
对于这种情况,我们需要使用ssh密钥来认证github帐户
导航到github – >设置 – > SSH和GPG密钥(部分) – >添加“新SSh密钥”,复制公钥( $ ssh-keygen #generate new key
))并粘贴密钥输入字段。 一旦添加密钥,使用这个命令“ $ ssh -T git@github.com
”检查身份验证。 它会显示下面的输出
Hi <xxxxxxxx>! You've successfully authenticated, but GitHub does not provide shell access.
现在它工作正常!