1

I followed the following procedure:

  • Created an SSH key;
  • Enabled SSH in Atlassian Stash;
  • Added SSH key for the Stash account called Capistrano (already used by Capistrano to successfully connect using username and password to Stash)
  • Tested the SSH connection using the command git clone ssh://git@stash.domain.com:7999/project/repository.git and the repository is successfully cloned;
  • Changed the following line to config/deploy.rb in Capistrano project directory: set :repo_url, 'ssh://git@stash.domain.com:7999/project/repository.git'

The problem is that executing the command cap production git:check I get the following error lines and the deployment is cancelled:

INFO [8b21e06e] Running /usr/bin/env mkdir -p /tmp/capistrano_project_name/ as deploy@host.domain.com
DEBUG [8b21e06e] Command: /usr/bin/env mkdir -p /tmp/capistrano_project_name/
INFO [8b21e06e] Finished in 0.292 seconds with exit status 0 (successful).
DEBUG Uploading /tmp/capistrano_project_name/git-ssh.sh 0.0%
INFO Uploading /tmp/capistrano_project_name/git-ssh.sh 100.0%
INFO [376577ce] Running /usr/bin/env chmod +x /tmp/capistrano_project_name/git-ssh.sh as deploy@host.domain.com
DEBUG [376577ce] Command: /usr/bin/env chmod +x /tmp/capistrano_project_name/git-ssh.sh
INFO [376577ce] Finished in 0.036 seconds with exit status 0 (successful).
INFO [2ed5c706] Running /usr/bin/env git ls-remote --heads ssh://git@stash.domain.com:7999/project/repository.git as deploy@host.domain.com
DEBUG [2ed5c706] Command: ( GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/capistrano_project_name/git-ssh.sh /usr/bin/env git ls-remote --heads ssh://git@stash.domain.com:7999/project/repository.git )
DEBUG [2ed5c706]        Permission denied (publickey).
DEBUG [2ed5c706]        fatal: Could not read from remote repository.
DEBUG [2ed5c706]
DEBUG [2ed5c706]        Please make sure you have the correct access rights
DEBUG [2ed5c706]        and the repository exists.
(Backtrace restricted to imported tasks)
cap aborted!
Exception while executing as deploy@host.domain.com: git exit status: 128
git stdout: Nothing written
git stderr: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Tasks: TOP => git:check
(See full trace by running task with --trace)

I already tried to simply change the variable to set :repo_url, 'ssh://git@stash.domain.com:7999/project/repository.git' but I receive the same error. Anyone successfully connecting Capistrano to Stash via SSH? Could you please suggest how I can debug it? I would like to avoid to use usernames and passwords in my Capistrano configuration files.

SQB
  • 3,926
  • 2
  • 28
  • 49
itwebdeveloper
  • 699
  • 1
  • 7
  • 15

1 Answers1

2

A simplistic answer, but I would guess that Capistrano is picking up the wrong key. I'd suggest that you check the default ssh key for the deployment user. So, if capistrano is set to log into the server using deployuser, see what key deployuser picks up. It can be helpful to test with ssh -T git@stash.domain.com -p 7999 and see what comes back.

will_in_wi
  • 2,623
  • 1
  • 16
  • 21
  • Thanks for you answer, @will. Unfortunately when I execute (changing the string with my domain) the command `ssh -T git@stash.domain.com:7999` I'm getting back: `ssh: Could not resolve hostname stash.domain.com:7999: Name or service not known` while `ping stash.domain.com` works correctly, I suppose this is because the port number is appended to the domain. – itwebdeveloper Jun 05 '15 at 16:07
  • Thanks, @will_in_wi. The reason is that I added the key of the deployment management machine (source) and not of the deployment system (target) to Stash, so it was not picking up any key. With your command I was able to debug, create the SSH key in the production servers and add them to Stash. – itwebdeveloper Jun 08 '15 at 15:38