SSH Keys and auto-login

If you look around on the web, most descriptions of how to get SSH Keys setup are really verbose, and in particular, assume you know everything about everything… This is typically NOT the case.

I’m going to attempt to explain how to automatically log in from one PC to another with SSH client and server, and on windows using PuTTY and puttygen.exe.


Assuming your SSH server is already set up, we’ll move right along into how to configure the CLIENT.

One thing to consider is that once we’re done configuring everything, what we’re doing is allowing remoteUser to connect to remoteMachine.com from our specific computer. This doesn’t let us auto-login from ANY computer, so don’t blame me later when it doesn’t work on your grandma’s computer.

First thing’s first, is we need to generate our public key.

For Linux:

  • Run ssh-keygen -t rsa
  • To avoid having to type in a password (that’s why we’re doing this right?) don’t supply a passphrase.
  • By default it will put the files in ~/.ssh/ as id_rsa (your private key) and id_rsa.pub (for your public key).

For Windows:

  • Download puttygen.exe from the PuTTY download page.
  • Click the “Generate” button, and move the mouse around to randomize input.
  • Once done, save your private key somewhere you’ll find it quickly.
  • To avoid having to type in a password (that’s why we’re doing this right?) don’t supply a passphrase.
  • Save or keep track of your public key for the next section.
  • In PuTTY, create or edit an existing session, and supply the value Connection > SSH > Auth > Private key for authentication with the private key you just saved to your disk.
  • I also suggest populating Connection > Data > Auto-login username for an easier connection.

Now that we’ve generated our keys, we can tell the server to accept us. This is easily done by pasting our PUBLIC keys into ~/.ssh/authorized_keys on the SERVER. For Linux it was our id_rsa.pub, and for Windows it’s either the file you saved, or the key it dumped out in the puttygen.exe application. If the folder/file doesn’t exist, create it with the CHMOD of 600 (or SSH server will ignore it). Remember that the .ssh files we want to edit are those of the user we want to gain access as.

One extra side note worth mentioning, your keys are generated based off a lot of different things, including the environment, hardware, user, etc. What this means is that if you’re connecting from Windows in cygwin, it will generate a completely different key than that of puttygen due to the environment change. Also note that if you have multiple Windows users, they can not share the same key even though they come from the same hardware. This isn’t really documented anywhere, but there you have it..

That’s it! You should now be able to login without typing a password from Windows or Linux.

Advertisements

About killerspaz

I'm a developer that loves to tinker with cutting edge technology. I have recently been playing with the Flash Platform (AS3/Flex), Android (custom roms, replacement apps, scripting), and looking at opportunities in the mobile markets.

Posted on 03.27.2009, in Tools and tagged , , , , . Bookmark the permalink. Leave a comment.

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

%d bloggers like this: