Use SSH agent forwarding to deploy via Capistrano

Setting up and maintaining deploy keys in github can be annoying. If you’re looking for a workaround, follow github’s instructions to deploy using your own personal SSH key.

Moving forward, we’ll assume you’ve generated SSH keys on your local machine.

Step 1: add a few lines to the ~/.ssh/config file on your local machine. We’re deploying to example.com, so we’ll need these lines:

Host *example.com
  ForwardAgent yes

Step 2: add a line to your capified project’s config/deploy.rb file

ssh_options[:forward_agent] = true

That’s it! Next time you deploy, capistrano will ssh into the server and clone the repo using your local user’s ssh keys. Very nice.

Special thanks to macat for helping me figure this out.


Update: even after adding ForwardAgent yes in my ~/.ssh/config, this wasn’t working on my laptop (running OSX Lion).

I re-read the github instructions and found that ssh-add -L returned nothing.

So I ran this to add my ssh key to the authentication agent:

ssh-add ~/.ssh/id_rsa

And it works!

Comments are closed.