Public: Concord Software Projects : Capistrano ssh and git
This page last changed on Mar 25, 2009 by stepheneb.
Capistrano will look at your .ssh/config settings by default when deploying to a remote host. It will try to find the first host entry which matches your deploy host. For that reason, you want to set your remote username in your .ssh/config file. If no user is specified it will attempt to use what ever is set as $USER on the host you are running cap from.
Here is an excerpt from my config file:
(The ForwardAgent lines are irrelevant for this discussion, but are nice to have around)
A copy of your public key should exist in .ssh/authorized_keys on the deploy host. See http://confluence.concord.org/display/TSC/Automatic+ssh-agent+startup+for+shell+users for more info on that.
If you are not running a ssh agent, you will be asked for the keys passphrase once.
I though it might be interesting to describe the path I took to get to the same answer.
I had this in ~/.ssh/config:
That along with a public key setup allows me to login to all the *.concord.org servers.
NetSSH can login using my public key:
But Capistrano which uses the Ruby Gem NetSSH didn't work.
I opened the code for the Capistrano and NetSSH gems in my editor and found the code in question by searching for ".ssh', 'user', and 'config'.
Here's the real clues starting at line 43 in file: /Library/Ruby/Gems/1.8/gems/net-ssh-2.0.11/lib/net/ssh/config.rb
And running this in Ruby IRB:
returned an empty hash
This ssh man page was helpful:
Adding a *.concord.org Host value before the User parameter in ~/.ssh/config allows the Ruby Net::SSH gem to find the sbannasch username:
Now the result in Ruby is:
And cap deploy now connects to the server correctly.
|Document generated by Confluence on Jan 27, 2014 16:52|