Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capistrano 3 deploy fails connecting to GitHub - Permission denied (publickey)

I have the following deploy script set up with Capistrano v3 and capistrano/symfony gem. I am deploying to an AWS EC2 instance with Ubuntu 14.4 I am connecting with a .pem file downloaded from AWS. I have the following in my deploy.rb

set :pty, true

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

when deploying with

bundle exec cap staging deploy --trace

The script connects fine but fails on this

INFO [4fd1b02c] Running /usr/bin/env git ls-remote --heads [email protected]:MyName/Myproject.git as [email protected]
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 [email protected]: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 [email protected]: 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

I don't know why forward_agent is not working?

I have been trying to follow this guide - https://developer.github.com/guides/using-ssh-agent-forwarding/#testing-ssh-agent-forwarding

but when I get to this

echo "$SSH_AUTH_SOCK"

It prints a blank line.

Also if I run this on the server it says command not found

sshd_config
like image 237
Patrick Avatar asked Dec 24 '22 13:12

Patrick


1 Answers

Double-check that the user running Capistrano has ssh-agent running and has ssh-added the relevant key.

Here are some good guides:

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

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

like image 168
will_in_wi Avatar answered Dec 27 '22 21:12

will_in_wi