Capistrano deploy with bitbucket - Permission deni

2019-05-30 03:13发布

问题:

After adding public key to bitbucket acct, ssh -T git@bitbucket.org returns (in windows):

The authenticity of host 'bitbucket.org (131.103.20.167)' can't be established.
RSA key fingerprint is 65:8c:1b:f2:6f:91:6b:5c:3b:ec:4a:46:46:74:7z:40.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'bitbucket.org' (RSA) to the list of known hosts.
logged in as myusername.

You can use git or hg to connect to Bitbucket. Shell access is disabled.

We verified that bitbucket.org has been added to known_hosts. The cap deploy command returns:

Host key verification failed.
fatal: The remote end hung up unexpectedly

We added the following 2 lines to deploy.rb file:

ssh_options[:forward_agent] = true
default_run_options[:pty] = true

Now cap deploy returns error:

 Permission denied (publickey).

Keys are not passphrase protected. If the key is accepted by bitbucket(ssh -T returns right info), why we still have the error of Permission denied.

回答1:

Have you run the ssh -T git@bitbucket.org command on the remote server, and confirmed it there? I've just checked a Linux server I deploy onto with Capistrano, and bitbucket.org is listed in the deploying user's .ssh/known_hosts files (it's hashed, but ssh-keygen -F bitbucket.org shows it).

Capistrano SSHes into the remote server, and runs the git checkout from there. It needs permission to connect to Bitbucket, although the access is granted from the source machine, via the :forward_agent option.