Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ssh problems during deploy with capistrano

I'm getting permissions errors while trying to deploy my rails app to a friend's server. I'm running rails 3.1.3, ruby-1.9.2-p290, capistrano 2.11.2, Mac OS 10.6.8, and we have ssh keys set up. However, we can't figure out where the permission issues are coming from. We think it might be that capistrano is trying to push the code from the git repo AS THE GIT USER to the deploy directory, or something like that. But this is our first deploy attempt, so we're not sure. Any help would be hugely appreciated!

Oh, and here's some more details that my friend told me to specify: appsrv-04.example.ca is the canonical FQDN of the host, and project.example.ca is a CNAME pointing to the A record of appsrv-04.example.ca. The known_hosts file for the git and deploy users contains all of appsrv-04, appsrv-04.example.ca, project, and project.example.ca.

Below is the output from running cap deploy:update.

[user@workstation]~/Code/projectapi $ cap deploy:update
 * executing `deploy:update'
  ** transaction: start
  * executing `deploy:update_code'
updating the cached checkout on all servers
executing locally: "git ls-remote ssh://[email protected]/usr/local/git_root/projectapi.git master"
Enter passphrase for key '/Users/user/.ssh/id_rsa': 
 command finished in 4478ms
* executing "if [ -d /usr/local/www/sites/project.example.ca/public/shared/cached-copy ]; then cd /usr/local/www/sites/project.example.ca/public/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard e71d220f299271522517f7b4f028a9275d53326a && git clean -q -d -x -f; else git clone -q ssh://[email protected]/usr/local/git_root/projectapi.git /usr/local/www/sites/project.example.ca/public/shared/cached-copy && cd /usr/local/www/sites/project.example.ca/public/shared/cached-copy && git checkout -q -b deploy e71d220f299271522517f7b4f028a9275d53326a; fi"
servers: ["project.example.ca"]
Enter passphrase for /Users/user/.ssh/id_dsa: 
[project.example.ca] executing command
 ** [project.example.ca :: err] Permission denied, please try again.
 ** [project.example.ca :: err] Permission denied, please try again.
 ** [project.example.ca :: err] Permission denied (publickey,password).
 ** [project.example.ca :: err] fatal: The remote end hung up unexpectedly
  command finished in 650ms
*** [deploy:update_code] rolling back
 * executing "rm -rf /usr/local/www/sites/project.example.ca/public/releases/20120222225453; true"
servers: ["project.example.ca"]
[project.example.ca] executing command
command finished in 465ms
failed: "rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell '1.9.2-p290@project' -c 'if [ -d /usr/local/www/sites/project.example.ca/public/shared/cached-copy ]; then cd /usr/local/www/sites/project.example.ca/public/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard e71d220f299271522517f7b4f028a9275d53326a && git clean -q -d -x -f; else git clone -q ssh://[email protected]/usr/local/git_root/projectapi.git /usr/local/www/sites/project.example.ca/public/shared/cached-copy && cd /usr/local/www/sites/project.example.ca/public/shared/cached-copy && git checkout -q -b deploy e71d220f299271522517f7b4f028a9275d53326a; fi'" on project.example.ca

And here's my deploy file:

$:.unshift(File.expand_path('./lib', ENV['rvm_path'])) 
require "rvm/capistrano"          

set :application, "Project"

set :scm, "git"
set :repository,  "ssh://[email protected]/usr/local/git_root/project.git"
set :user, "deploy"

#set :rvm_bin_path, "/usr/local/rvm/bin"
set :rvm_ruby_string, "1.9.2-p290@project"

ssh_options[:forward_agent] = true

set :branch, "master"

set :deploy_via, :remote_cache

set :deploy_to, "/usr/local/www/sites/project.example.ca/public/"

set :use_sudo, false

set :domain, 'project.example.ca'

role :app, domain
role :web, domain
role :db,  domain, :primary => true
like image 538
J K Avatar asked Feb 23 '12 17:02

J K


1 Answers

You've almost certainly diagnosed this issue correctly; you're trying to check out the github repository as the deploy user and the forwarded key isn't being set up correctly. It looks like you have forward_agent turned on in Capistrano... are you adding your key to your agent so that it gets forwarded correctly?

Try doing that with ssh-add ~/.ssh/id-rsa and deploying again.

like image 180
Veraticus Avatar answered Oct 04 '22 23:10

Veraticus