Jul. 11 2011

Using a Key-Pair To Automatically Login with PuTTY

Okay, here’s a little tutorial to teach you how to use a key to log into an SSH server. It’s actually quite simple after I found out how to do it, thanks to this guy.

  1. Log into your SSH server using PuTTY.
  2. In your home directory (if you don’t automatically go there at login, you can get there by using ~), create a directory called .ssh and chmod it to 700. This will hold your personal preferences and such for the SSH server.
  3. Inside the .ssh directory, create a blank file named authorized_keys using touch authorized_keys and chmod it to 600. This will be where your public key will be kept after we generate it.
  4. Generate a public and private key using ssh-keygen -t dsa. Use the filename it provides–it’s not important, except for the next step–and type in a secure passcode from keeping anyone from generating a private key without authorization. (Mine saved as id_dsa, so I’ll use that from here on out.)
  5. Put the contents of your public key to into your authorized_keys file using cat id_dsa.pub >> ~/.ssh/authorized_keys.
  6. Download your private key (id_dsa without an extension) to your PC.
  7. Load it into PuTTYgen–which can be downloaded from here–and use your passcode to open it. By default, the PuTTYgen load window looks for PuTTY Private Key files (.ppk), so you’ll need to use the drop down menu to select All Files (*.*) instead.
  8. Click the Save Private Key button to convert the SSH private key file into the PuTTY private key format so you can use it with PuTTY.
  9. Open up PuTTY. Under the Connection branch, open the SSH branch by clicking the little plus sign. Click on Auth to show the Options for controlling SSH authentication options.
  10. In the Authentication Parameters box, select your PuTTY private key file.
  11. If you have a session already loaded, make sure you go back to the Session branch to save the session again.
  12. Click the Open button and you’ll be prompted for your passcode to be logged in. If not, go back through all these steps before continuing on into the Pageant setup.

Automatic PuTTY Login with Pageant

If you just wanted the more secure login option with a key-pair, then you’re all set. However, if you constantly have 6 or 7 SSH windows open to your server, then let’s get the SSH authentication agent Pageant setup.

  1. Download and launch Pageant from here. It’s a self-contained executable so there’s no installation necessary.
  2. Right-click on the Pageant icon in your taskbar (it’ll be a little computer with a hat–kinda strange, actually.) and click the Add Key option.
  3. Find your PuTTY Private Key file and add it to the agent.
  4. Open up that saved PuTTY session and you’ll be logged right in!

The only caveat is that the program isn’t installed and not automatically set to start with your computer. But all you need to do is drag that file into the Startup folder in your Start menu (Win 98 and above have this folder). That’s the easiest way. There’s also several other ways to do it.

EDIT: So, Pageant doesn’t load keys automatically. Bummer. You have to call the program by command line to have it add the certificates at start up using C:\path\to\pagent.exe C:\path\to\private.ppk. If you’re using the registry, just put that as the command. If you’re using the Startup folder, put that line in a new file in the Startup folder called pagent.bat. You’ll still have to type your passcode each time, though.


1 comment

  1. August 25, 2017 at 9:34 am

    I see you don’t monetize your blog, don’t waste your traffic, you can earn extra cash every
    month because you’ve got hi quality content. If you want to know how to make extra money, search for: best adsense alternative
    Wrastain’s tools

Leave a Reply

Previous post:

Next post:

Last.fm interface from fmTuner (modified by me).

Twitter interface from HL Twitter.

Dedicated to my mom, Sharon. May she rest peacefully.
Love you always. (March 23, 1965 - November 12, 2011)

Unsupported Browser!

My site is designed for and currently displays best with modern browsers (and it looks like you don't have one!).

Everything should still function properly, but you won't be able to see all the fancy effects, text, or the way I intended my design to look.

Consider trying the latest version of either Firefox or Chrome... I think you'll like it!

Logan Bibby

P.S.: You can continue viewing my site by clicking the "close" link and you'll never see this again. :)