Passwordless remote login using Putty

It is quite easy to configure Putty to login to a server using a public/private key pair.

  • Create the key pair
  • Open the Puttygen.exe file and create a 1024 bit RSA-SSH2 key. After the keys have been created save them in a save place. Optionally you can give your private key a passphrase.

    puttygen

    The PuttyGEN window


    The important part here is that you have to copy the key that is showing in the textbox in using the context menu in puttygen. Selecting the key with the mouse and copying to the clipboard using CTRL-keys will not work. So with the content of the public key in your clip board you can close puttygen.

  • Preparing the remote server
  • There are several examples on the internet in how to assign your public key to the remote server but some of them are rubbish. I followed one just to end up with this error message.

    Houston we got a problem

    Something went wrong here


    So to avoid an error message like the one above there are two ways to apply the key to the remote machine.

    1. Use the copy that you still have in your clipboard
    2. Login to the remote server as the user that you want to use for passwordless login. Execute
      echo "ssh-rsa the content of your clipboard" >> .ssh/authorized_keys
      The double quotes and the prefix “ssh-rsa ” are necessary.

    3. Make a new copy of the existing key
    4. Open the public key in an editor like notepad++.

      The public key

      The recently created key in notepad++


      Before we can echo the key into the authorized_keys file on the remote server we have to amend it slightly. The part that we are interested is starts with AAAA and ends with V7U=. That is your public key. Make sure that the whole key is not wrapped. So at the end you should have a long line starting with AAA and ending with 7U=. Now add the prefix ssh-rsa followed by a space to the beginning of that line. To make it easy to find the key in the file you can also add the comment at the end of the line. Key and comment must be separated by a space. So your final line is now starting with ‘ssh-rsa AA…’ and ending either with ‘…7U=’ or ‘…7U= myWorkstation’ or whatever comment you chose. Now surround the whole line with double or single quotes and copy it to the clipboard. Use the above command to add the key to the authorized_keys file.

        That is all you need to do on the remote server.

      1. Prepare Putty to use the new key pair.
        1. Open putty and either create a new connection or load an already existing one
        2. The putty window

        3. Set the user name to the name that you want to login as.
        4. Set your user name in here

        5. Amend the key settings.
        6. Putty key settings

        7. Save your settings
        8. Save settings

        9. Test the new connection
        10. After opening the connection to the remote server you should see an output that is similar to this one.

          Login successful without a password challenge

          Login successful without a password challenge

I hope that this will help.

About Juergen Caris

I am 54yo, MSc(Dist) and BSc in Computer Science, German and working as a Senior Server Engineer for the NHS Lothian. I am responsible for the patient management system, called TrakCare. I am a UNIX/Linux guy, working in this sector for more than 20 years now. I am also interested in robotics, microprocessors, system monitoring, Home automation and programming.
This entry was posted in Applications, Beginner, Linux, Windows. Bookmark the permalink.

Leave a Reply

Your email address will not be published.