0

I'm trying to deploy with Capistrano3 connecting to git server by SSH. It is OK to connect to server by using normal git command. But using capistrano isn't.

Error message

cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as serveruser@xx.xx.xx.xx: git exit status: 128
git stdout: Nothing written
git stderr: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
fatal: The remote end hung up unexpectedly

deploy.rb

# config valid only for current version of Capistrano
lock '3.4.0'

set :application, 'Sample'
set :repo_url, 'ssh://serveruser@xx.xx.xx.xx:22/var/lib/git/public_git/sample.git'
set :deploy_to, '/app/Sample'
set :scm, :git

production.rb

server 'xx.xx.xx.xx', user: 'serveruser', roles: %w{app db web}, my_property: :my_value
role :app, %w{serveruser@xx.xx.xx.xx}, my_property: :my_value

set :ssh_options, {
  keys: %w(/Users/localuser/.ssh/id_rsa),
  forward_agent: false,
  auth_methods: %w(password)
  # password: 'please use keys'
}

Am I Missing any points?

tajihiro
  • 2,293
  • 7
  • 39
  • 60

2 Answers2

1

A wild stab in the dark, but here are a few things to try. I think you may need to specify a :user in your :ssh_options. You may be able to/have to remove teh ssh:// from your :repo_url. Judging from you key location, you may not even need the keys: in your ssh options. Also, make sure your public key is on the destination server (this probably goes without saying).

Brad Werth
  • 17,411
  • 10
  • 63
  • 88
  • As you commented, I tried several pattern. But still not work. `SSHKit::Command::Failed: git exit status: 128 git stdout: Nothing written git stderr: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password). fatal: The remote end hung up unexpectedly` – tajihiro Sep 23 '15 at 03:57
  • https://github.com/capistrano-plugins/capistrano-ssh-doctor ? from http://stackoverflow.com/questions/28375506/sshkitrunnerexecuteerror – Brad Werth Sep 23 '15 at 03:59
  • It is OK if I use git command. $ git push sample serveruser@XX.XX.XX.XX's password: Counting objects: 12, done. Delta compression using up to 4 threads. Compressing objects: 100% (11/11), done. Writing objects: 100% (12/12), 2.77 KiB | 0 bytes/s, done. Total 12 (delta 9), reused 0 (delta 0) To ssh://serveruser@xx.xx.xx.xx:22/var/lib/git/public_git/sample.git 1071234..ba863b5 master -> master Any difference? – tajihiro Sep 23 '15 at 04:18
  • Failed commands are 'cap deploy' and 'cap deploy:check'. Successful commands are 'cap deploy:check:directories' and 'cap deploy:cleanup'. I guess authentication problem something to do with git command. I'm still need help. – tajihiro Sep 23 '15 at 04:42
  • Are you running that git command from your workstation, or the server? Try forward agent true, maybe... – Brad Werth Sep 23 '15 at 05:08
  • Cilent machine is Mac. Server machine is CentOS. I command from Mac client machine. I tried forward agent true, but does not work. same error. – tajihiro Sep 23 '15 at 06:42
  • @tajihiro the command has to work from your server. Try sshing in and getting it working there.... – Brad Werth Sep 24 '15 at 21:14
1

99/100 times, this means that your SSH key is not getting to the Git server. It looks like you are successfully logging into the server. Check the following:

  • Are you using deploy keys or SSH Agent? If the former, make sure that the default key on the user account to which you are deploying on the server works. If the latter, make sure that ssh-agent is running and that you have ssh-added your key to it.
  • Log into the server and run ssh -Tv your-repo-url. It should return a message about successfully authenticating. If not, debug until this command works. The output from -v will help you know which keys it is using.
  • If you are using deploy keys, check to see whether your ssh keys are chmod 600 and the ~/.ssh directory is chmod 700, on the server. If this is not the case, make it so.
  • Use Capistrano SSH Doctor to help debug your connection.
will_in_wi
  • 2,623
  • 1
  • 16
  • 21
  • It is OK following description. `$ssh -Tv XX.XX.XX.XX -i ~/.ssh/id_rsa` But it cause error next description. `$ssh -Tv ssh://XX.XX.XX.XX/var/lib/git/public_git/sample.git -i ~/.ssh/id_rsa` `ssh: Could not resolve hostname ssh://XX.XX.XX.XX/var/lib/git/public_git/oauth.git: nodename nor servname provided, or not known` Is it matter of how to write url? – tajihiro Sep 28 '15 at 16:30
  • It was repository matter. I made server git repository again. It worked. `git init --bare --shared` . I guess I had missed --shared option. – tajihiro Oct 02 '15 at 07:37
  • And I generated new deploy key, in case. – tajihiro Oct 03 '15 at 03:20