Recent News

An SSH one-liner to authorize via public-key

Here's a two-part tip on SSH productivity--you can use public-key authentication and SSH's built-in configuration options to save some time every day.

1) Authorize your public key. If you're like me, it's a bother to remember each little step -- here's the one-liner I use for convenience.


  > ssh someuser@remotehost.com "echo `cat ~/.ssh/id_rsa.pub` >> ~/.ssh/authorized_keys" 

This will append your key to the remote host's list of authorized keys.

Don't have a public key yet? You can generate one with:


 > ssh-keygen 

You'll find a brand-new keypair in your ~/.ssh directory. Read up on public-key cryptography if it's new to you.

2) Now add the remote host to your (local) .ssh/config file:

1
2
3
Host rh
  Hostname remotehost.com
  User someuser

The SSH config file can contain many entries; just add this to the list. "Host" is an alias/nickname/shortcut of your choosing.

So, you can now SSH to your remote host with:


 > ssh rh

This will save you a little typing. Public-key authentication is a "best practice" anyway -- it's good to develop the habit. For example, this is the only way to SSH into Amazon EC2 instances, and for administrators, it means you can share access to a SSH account (say, a deployer) without floating the password around.

Bonus tip: If you find Capistrano and Net::SSH behaving quirkily, make sure you have the latest versions of both. Recent updates to Net::SSH have included various updates and fixes relevant to public-key authentication.

cf. http://net-ssh.rubyforge.org/
cf. http://groups.google.com/group/capistrano/

Comments



Post a comment

cementhorses.com

Categories

Cement Horses Pics

Archives