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
:
The only other thing you need to do is tell the SSH agent about your key.
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.