Capistrano, Git and SSH keys
This trick has been around for a while, but I’ve talked with several people that didn’t know about it.
When deploying apps with Capistrano, your server needs to have access to the Git repository. Generating an SSH key for each server is a bit of a pain, but there’s an easier way: SSH agent forwarding enables you to use any of your local SSH keys on the server. It’s really easy to set up.
Enable SSH forwarding in deploy.rb:
set :ssh_options, {:forward_agent => true}
The only other thing you need to do is tell the SSH agent about your key.
$ ssh-add -K
The -K option only works on OS X and it adds your key to your keychain so you don’t have to run ssh-add after you reboot (and if you have a passphrase set, you don’t have to type it every time). You can also pass it the path to an SSH private key in a different location.
Now the server can pull from any Git repository that you have access to.
3 comments
This showed up right on time for me to use it. Thanks!
Though I don’t use Capistrano, I found this really useful as I’m allowed only one public ssh key per git user. This saved me from greating another git account which would look stupid in the commit logs as this would should two users making commits for one person.
Thanks
Speak your mind: