Is this your first visit? You may want to subscribe to the feed.

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.

Code: capistrano, deployment, git, rails, ssh Jun 23, 2009 ● updated Jun 25, 2009 3 comments

3 comments

  1. This showed up right on time for me to use it. Thanks!

    Erik Ostrom Erik Ostrom June 24, 2009 at 05:00 PM
  2. 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

    Richard H Lee Richard H Lee November 02, 2009 at 06:31 AM
  3. Useful, can’t get out from
    • [xxx :: err] Permission denied (publickey).
    • [xxx :: err] fatal: The remote end hung up unexpectedly error
    Giovanni Giovanni November 27, 2009 at 04:14 AM

Speak your mind:

*

*


* I hate spam and will never sell or publish your email address.

(You may use textile in your comments.)

Subscribe

Browse by Tag