0
votes

I have a Capistrano script that deploys some rails code to a ubuntu box. My git repo is not on github but rather on our companies server. I have configured capistrano like so...

set :repository, "ssh://non-root-user@mydomain.com/opt/git/hub/app.git"

When I deploy using the copy feature...

set :deploy_via, :copy

It works without issue. But when I deploy using a remote cache...

set :deploy_via, :remote_cache

It fails with the error message

 Permission denied, please try again.←[0m
 Permission denied, please try again.←[0m
  Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).←[0m
 fatal: The remote end hung up unexpectedly

This is during the deploy:update_code task. My guesses are this error is showing up for possibly the following reasons?

1 - Maybe I need to setup some keys? My git repo server is different than the target deployment server, but both are hosted by my company. Suggestions appreciated.

Edit: I tried ssh_options[:forward_agent] = true default_run_options[:pty] = true and it would prompt me for a password, I would enter the correct password but it would say permission denied anyways. I am no longer deploying as root.

2

2 Answers

0
votes

I think your assumptions are both correct. Capistrano is trying to login as root. There are 2 options you can do.

  1. Turn on root password (assuming PermitRootLogin is yes by default in /etc/ssh/sshd_config)

(remote)$ sudo passwd root

  1. Copy the content of your id_rsa.pub on your local machine and append to /root/.ssh/authorized_keys file on your remote machine.

If you don't have ~/.ssh/id_rsa.pub, you can set up your key on your local machine like this:

(local)$ ssh-keygen -t rsa

The 2nd option is preferred because you don't have to configure anything else on your remote machine except the authorized_keys.

reference link1 link2

0
votes

It is likely that available keys on the deployment server were not able to authenticate for your repository.

You can register the updated key to the deployment server like you do for your other keys, but you can also use agent forwarding (Github article):

It allows you to use you local SSH keys instead of leaving passphrase-less keys sitting on your server.

Capistrano tells your ssh client to use agent forwarding with this:

set :ssh_options, :forward_agent => true