Logging in via putty (ssh) without using a password

Increase security! See how to log in via Putty (SSH) without using a password, using keys. A complete step-by-step configuration guide.

The ssh protocol offers several methods of user authentication. Besides the most popular one - login and password - we can use certificates, which are a pair of keys (private and public). During the authorization process, the server, having the public key, creates a so-called challenge, which only the user holding the private key of the same pair can decrypt and use to confirm their identity. This solution has its advantages and disadvantages, with the advantages outweighing them.
ADVANTAGES:

  • We're protected against keyloggers.
  • Someone eavesdrops on the session, which is much harder but possible. On the next connection the server will generate a different challenge, and unfortunately our amateur intruder, not having the private key, won't be able to generate the correct response, and the previously recorded one won't be valid.
  • A "brute force" method is practically impossible.

There's probably only one downside, namely the possibility of the private key being physically, or less often remotely, stolen from the client machine. So much for the theory, let's get to it.


  • We perform the following steps on Windows

  • We download and run the program puttygen
  • We select the option: (x) SSH-2 RSA (we choose the key length according to our needs, but not less than 1024), click generate, and then wave the mouse over the empty field (that's not a joke, you really have to wave it)
  • We save the private key in a place known only to you (it will be used by putty)
  • We perform the following steps on the server

  • We save the public key and then transfer it to the server
  • Once on the server, we convert our key to openssh format with the command:
    ssh-keygen -if public_key > public_key_openssh_format
  • We change the .ssh directory's permissions with the command: chmod 700 .ssh
  • We copy our public key (openssh_format) into the .ssh/authorized_key file:cat public_key >> .ssh/authorized_key
  • We delete the already copied file with the command:rm public_key
  • We again change the .ssh directory's permissions: chmod 600 .ssh/authorized_key
  • We perform the following steps on Windows

  • We start putty. We select the saved configuration. We go to Connection=>Data, providing our login in the Auto login username field
  • Then we go to SSH=>Auth, providing the path to our private key in the Private key file for authentication field
  • We go back to Session, saving the configuration