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://git@appsrv-04.example.ca/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://git@appsrv-04.example.ca/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://git@appsrv-04.example.ca/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://git@appsrv-04.example.ca/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

```
['https://Stackoverflow.com/questions/9417618', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1034602/']
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.
Problem solved. The virtual host was created by cloning an existing one and changing the IP. I updated the /etc/hosts file to use the new hostname, but apparently not the new IP. So when the deploy user was trying to ssh as the git user... it was failing because there is no git user on the IP it was using.