Automating Secure Shell Login using Putty

Putty is an ssh client for Microsoft Windows which can automate secure logins to remote computers. This tutorial allows you to automate these logins using your personal public/private key pair.

Putty can be downloaded from here:

http://www.chiark.greenend.org.uk/~sgtatham/putty/. Download and install the entire putty distribution.

Love a Career in Telecoms
Love a Career in Telecoms

During this procedure the following high-level steps are taken:

  • First, create a public-private key pair using puttygen.
  • Second, create a session for logging into a particular host. This session will include the IP address and can include the username and location of your private key
  • Lastly, add your public key to the host you’ll be logging into.

Each of these steps is detailed below.

Create a private key

Follow the Putty documents for using the using puttygen application. Create a private key with a passphrase. Choose a passphrase that is easy for you to remember, but is long, like a complete sentence, with misspellings or numbers included.

As an example only, “A p3nny sav3d is a p3nny 3arn3d”.

Save the private key in a directory only accessible to you.

Create a Putty session for each host you access

  1. Launch the Putty configuration utility.
  2. In the Connection -> Data, enter the name of the user to login with
  3. In the Connection -> SSH -> Auth, enter the path to the private key file. This path is where the private key is stored on your PC.
  4. In the Session category, enter the IP Address of the host
  5. Finally, in the Session category, save the session using a helpful name

Place your public key on the host you’ll be logging into

On a UNIX/Linux host, using $HOME as the path to the home directory of the user you login as.  You’re going to make a directory called “.ssh” to store ssh-specific files. Then you’ll add a file for authorized keys.

  1. mkdir .ssh
  2. cd .ssh
  3. vi authorized_keys
  4. Launch the puttygen application on your PC and follow the directions to load your private key.
  5. Select and copy the public key text from the puttygen window.
    In the active window on the host, paste into the vi editor using SHIFT-INSERT.
  6. Save and quit the editor.
  7. Then make the directory and file executable.
    chmod go-w $HOME $HOME/.ssh $HOME/.ssh/authorized_keys
  8. To login using the session you’ve created, launch the putty application.
  9. Select from the Saved Settings list the session you created in step 5, above.
  10. Click Load.
  11. Click Open
  12. You should be prompted to enter your passphrase. Enter the passphrase.

The login should be successful. Resolve any errors before continuing.

Automating passphrase Entry

The steps above require you to enter your passphrase every time you log in to this host. That’s way too much work! Entering the passphrase can be automated using the Pagent application included in the putty distribution.

  1. Launch the Pagent application.
  2. Click Add Key.
  3. Select the path to the private key you created above. Click Open.
  4. Pagent will prompt you to enter the passphrase you entered when the private key was created.
  5. Now when you select a Putty session, you will be logged in automatically.

You should be logged into the host without being asked to enter your password or your passphrase. Resolve any errors before continuing.

Automated Login

Lastly, a shortcut can be created which logs you in with a single double-click.

  1. Find the Putty application on your PC. Right-click and select Create Shortcut.
  2. Right-click on the shortcut and select Properties.
  3. Click on the Shortcut tab of the Properties dialog box.
  4. In the Target box append load <session> where <session> is the Putty session name created above.
  5. Rename the shortcut with a meaningful name.
  6. Double-click the shortcut to login to this host.

Join the Conversation

1 Comment

  1. @Kim Smith.

    Glad you liked the article. I hope by automating your logins it saves you significant time. I login to about a dozen systems each day, and the time saved not typing and not looking up passwords really adds up.

    Thanks for reading!

Leave a comment

Your email address will not be published. Required fields are marked *