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 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.

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”

Create a 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. Last step, in the Session category, save the session using a helpful name

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

On a UNIX host
cd $HOME
Where $HOME is the path to the home directory of the user you login as. Then, make a directory for ssh.
mkdir .ssh
cd .ssh
vi authorized_keys
Next, launch the puttygen application on your PC and follow the directions to load your private key.
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. Save and quit the editor. Then make the directory and file executable.
chmod go-w $HOME $HOME/.ssh $HOME/.ssh/authorized_keys

Using your session

  1. To login using the session you’ve created, launch the putty application.
  2. Select from the Saved Settings list the session you created in step 2.3, above. Click Load.
  3. Click Open
  4. You should be prompted to enter your passphrase. Enter the passphrase. You should login successfully. Resolve any errors before continuing.

Automating passphrase Entry

Using the steps above requires you to enter your passphrase every time you login to this host. 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 private key you created in section 2.2, above. Click Open.
  4. Pagent will prompt you to enter the passphrase you entered when the private key was created.
  5. Now follow the steps in section 3, above.

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, on windows a shortcut can be created that does this all in 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 name created in step 2.3, above.
  5. Double-click the shortcut to login to this host.

One Reply to “Automating Secure Shell Login using Putty”

  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 Reply