Setting up PuTTY to do passwordless logins using pre-shared key

  • Posted on
  • by
  • in

Setting up PuTTY to do passwordless logins using pre-shared key

Seems I've been here before: http://cygwin.com/ml/cygwin/2012-01/msg00284.html

This site seems helpful: https://support.hostgator.com/articles/specialized-help/technical/ssh-keying-through-putty-on-windows-or-linux

Generating your ssh keys

You need to use PuttyGen to generate your ssh keys to share. One problem is that Putty does it's own form of ssh keys which is non-standard or at least non-Unix like. Once you install PuttyGen you should generate your key. SSH-2 DSA is more secure than the default SSH-2 RSA keys so toggle that on then do generate, then move the cursor around the blank area. PuTTYgen uses this movement to generate the key's randomness.

Once this is generated, you can set a key comment, or a passphrase. The comment isn't important, as it's just a label, but the passphrase will require that you enter this passphrase when using the key. If you're trying to have a "passwordless login" then this should be left blank.

Now click Save Public Key, and save this file to a name of your choosing somewhere safe on your hard drive. Please remember the location of this file, as it is needed later. Then do the same for Save Private Key.

Installing your ssh keys into the server

Now that we have the keys generated and saved, we need to getthe keys on the server. Copy the data inside the putty window under Public Key for pasting into SSH authorized keys file. The key appears to be to put these keys into your ~/.ssh/authorized_keys2 file not you're ~/.ssh/authorized_keys file. You want to putthis into your NFS home directory not your Windows home directory. Why we maintain two different sets of home directories is unknown.

Note: If you don't have a .ssh directory on your Unix/Linux machines then execute ssh-keygen -t dsa on Linux to create that and your DSA keys.

Note 2: If a Linux machine does not use your NFS mounted home directory then you'll have to duplicate your home environment and things like ~/.ssh on the machines that do not share your one home directory.

Make sure your ~/.ssh/authorized_keys2 is set to 600.

Setting up colored sessions for PuTTY and tying that to shortcuts

It's best to set up sessions in putty. A session is merely a set of configuration parameters tied to a name. We will create sessions for different types or categories of machines then invoke them with different machine names. We will set up session for dev/test/prod environments.

In putty do the following:

  • Window: Lines of scrollback - you might want to set this to something larger than 200 like maybe 2000.
  • Window: Colours: Set Default Background and Default Bold Background to some color. You may want to use a theme of dev blue, test 3D orange and prod red, for example. I also change Default Foreground to a solid white and Default Bold Foreground to a bright yellow. This setting will be the main setting to change between dev/test and prod.
  • Connection: Data: Auto-login username. Set this to your username (e.g. adefaria)
  • Connection: SSH: Auth: Private key file for authentication: Browse to where you put your generated Putty Private Key.
  • Connection: SSH: X11 - toggle on Enable X11 forwarding. Consider installing Cygwin's Xorg server

Then go back to the Session page and enter a name for your Saved Session and click save. Next you can change that name, go toConnection: Colours, set up your color scheme for test or prod and save those sessions. Now you have dev/test and prod sessions colored to your liking.

Executing PuTTY sessions

Now you can set up shortcuts to use these saved session parameters but apply them to different machines like so:

C:\Program Files\Putty\Putty.exe -load dev cm-job-ldev01
C:\Program Files\Putty\Putty.exe -load test cm-job-ltest01