Capistrano and Git - Using Same Box for GIT and Deployment

May 22, 2008

Been a pain getting my git-server and web-server to communicate via ssh as they are the same box. This is partly to do with the fact that my git user is very restricted

I have two users on my server

  1. Deploy - who is responsible for deploying applications
  2. Git - who is responsible for Git things

Using capistrano my deploy user has to get the latest src from the git user. Using ssh to do this kept giving me ssh errors.

In the end I had to create a key pair for deploy and put the public key in the git users authorized keys file. Because I could not log in as the git user I had to do this as root.

mv /home/deploy/.ssh/id-rsa.pub /home/git/.ssh/deploy.pub

then backup the authorized keys file and then change permissions so I can write to it.

cd /home/git/.ssh
cp authorized-keys authorized-keys.old
chmod 777 authorized-keys   # give all access
cat deploy.pub >> authorized keys # must use double arrow or will overwrite not append!!
chmod 600 authorized-keys # has to have minimal permissions or ssh will complain

Warning

Instructions above are very rough and probably not totally accurate be careful

Update

May well have been able to do this using

set :ssh_options, { :forward_agent => true }

Which forwards ssh keys from the local machine through the web-server to the git-server