SSH without a password


I’m working my way through the Debian Administrator’s manual and came across an amazing tidbit of information about ssh: you don’t need to enter your password all-the-bloody-time! Now, I’ve been using ssh for almost 2 years and never bothered to go through the man file, so I was pleasantly surprised, and made a note to look it up.

And I did. And it was bloody simple! In a moment, I’ll share it with you, but frankly, that’s one thing about linux – you’re always learning. I’ve fiddling with it for 2 years and I still feel like I’m a hack, a n00b! That’s the bad part, but the good part is, I think I know a lot more about the innards of linux than I did of Windows.

So, here’s the how bit.

$ssh-keygen

Run this on the machine you want to ssh in from. Your public and private keys will be generated and stored into the .ssh folder in your home directory (i.e. ~/.ssh). The relevant file is id_rsa.pub – this is your public key. Now, on your destination server, the one you want to ssh into, you add should the contents of this file to the ~/.ssh/authorized_keys file.

In short, append the remote id_rsa.pub to host authorized_keys file.

In my case I had no authorized_keys file, so I copied the id_rsa.pub file and renamed it to authorized_keys.

To test it out, I then tried a new ssh connection and voila, no password prompt.

In cases where this doesn’t work there are a few things that must be in order, so do look at the manpage for ssh or ping me in case you run into issues. And I think it’s in cases where it doesn’t work, that you learn the most!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s