This is an old revision of the document!

Documentation » Getting Started » Protocols » SSH »

Using Public Keys for Authentication

This article explains public key authentication in general. You may want to see guide to setting up public key authentication instead.

Do not confuse your user key pair used for authentication with host public key verification. Learn about all SSH key types.

Advertisement

Introduction

Public key authentication is an alternative means of identifying yourself to a login server, instead of typing a password. It is more secure and more flexible, but more difficult to set up.

In conventional password authentication, you prove you are who you claim to be by proving that you know the correct password. The only way to prove you know the password is to tell the server what you think the password is. This means that if the server has been hacked, or spoofed, an attacker can learn your password.

Public key authentication solves this problem. You generate a key pair, consisting of a public key (which everybody is allowed to know) and a private key (which you keep secret and do not give to anybody). The private key is able to generate signatures. A signature created using your private key cannot be forged by anybody who does not have that key; but anybody who has your public key can verify that a particular signature is genuine.

So you generate a key pair on your own computer, and you copy the public key to the server under a certain name. Then, when the server asks you to prove who you are, WinSCP can generate a signature using your private key. The server can verify that signature (since it has your public key) and allow you to log in. Now if the server is hacked or spoofed, the attacker does not gain your private key or password; they only gain one signature. And signatures cannot be re-used, so they have gained nothing.

There is a problem with this: if your private key is stored unprotected on your own computer, then anybody who gains access to that will be able to generate signatures as if they were you. So they will be able to log in to your server under your account. For this reason, your private key is usually encrypted when it is stored on your local machine, using a passphrase of your choice. In order to generate a signature, WinSCP must decrypt the key, so you have to type your passphrase.

This can make public-key authentication less convenient than password authentication: every time you log in to the server, instead of typing a short password, you have to type a longer passphrase. One solution to this is to use an authentication agent, a separate program which holds decrypted private keys and generates signatures on request. WinSCP can use PuTTY’s authentication agent, called Pageant. When you begin a Windows session, you start Pageant and load your private key into it (typing your passphrase once). For the rest of your session, you can start WinSCP any number of times and Pageant will automatically generate signatures without you having to do anything. When you close your Windows session, Pageant shuts down, without ever having stored your decrypted private key on disk. Many people feel this is a good compromise between security and convenience.

Advertisement

There is more than one public-key algorithm available. The most common are RSA and ECDSA, but others exist, notably DSA (otherwise known as DSS), the USA’s federal Digital Signature Standard.1

Generating Keys

To generate a key pair, use the PuTTYgen application.

-----BEGIN PUBLIC KEY----- 30 82 02 0a 02 82 02 01 00 91 e8 54 92 d2 0a 56 b1 ac 0d 24 dd c5 cf 44 67 74 99 2b 37 a3 7d 23 70 00 71 bc 53 df c4 fa 2a 12 8f 4b 7f 10 56 bd 9f 70 72 b7 61 7f c9 4b 0f 17 a7 3d e3 b0 04 61 ee ff 11 97 c7 f4 86 3e 0a fa 3e 5c f9 93 e6 34 7a d9 14 6b e7 9c b3 85 a0 82 7a 76 af 71 90 d7 ec fd 0d fa 9c 6c fa df b0 82 f4 14 7e f9 be c4 a6 2f 4f 7f 99 7f b5 fc 67 43 72 bd 0c 00 d6 89 eb 6b 2c d3 ed 8f 98 1c 14 ab 7e e5 e3 6e fc d8 a8 e4 92 24 da 43 6b 62 b8 55 fd ea c1 bc 6c b6 8b f3 0e 8d 9a e4 9b 6c 69 99 f8 78 48 30 45 d5 ad e1 0d 3c 45 60 fc 32 96 51 27 bc 67 c3 ca 2e b6 6b ea 46 c7 c7 20 a0 b1 1f 65 de 48 08 ba a4 4e a9 f2 83 46 37 84 eb e8 cc 81 48 43 67 4e 72 2a 9b 5c bd 4c 1b 28 8a 5c 22 7b b4 ab 98 d9 ee e0 51 83 c3 09 46 4e 6d 3e 99 fa 95 17 da 7c 33 57 41 3c 8d 51 ed 0b b6 5c af 2c 63 1a df 57 c8 3f bc e9 5d c4 9b af 45 99 e2 a3 5a 24 b4 ba a9 56 3d cf 6f aa ff 49 58 be f0 a8 ff f4 b8 ad e9 37 fb ba b8 f4 0b 3a f9 e8 43 42 1e 89 d8 84 cb 13 f1 d9 bb e1 89 60 b8 8c 28 56 ac 14 1d 9c 0a e7 71 eb cf 0e dd 3d a9 96 a1 48 bd 3c f7 af b5 0d 22 4c c0 11 81 ec 56 3b f6 d3 a2 e2 5b b7 b2 04 22 52 95 80 93 69 e8 8e 4c 65 f1 91 03 2d 70 74 02 ea 8b 67 15 29 69 52 02 bb d7 df 50 6a 55 46 bf a0 a3 28 61 7f 70 d0 c3 a2 aa 2c 21 aa 47 ce 28 9c 06 45 76 bf 82 18 27 b4 d5 ae b4 cb 50 e6 6b f4 4c 86 71 30 e9 a6 df 16 86 e0 d8 ff 40 dd fb d0 42 88 7f a3 33 3a 2e 5c 1e 41 11 81 63 ce 18 71 6b 2b ec a6 8a b7 31 5c 3a 6a 47 e0 c3 79 59 d6 20 1a af f2 6a 98 aa 72 bc 57 4a d2 4b 9d bb 10 fc b0 4c 41 e5 ed 1d 3d 5e 28 9d 9c cc bf b3 51 da a7 47 e5 84 53 02 03 01 00 01 -----END PUBLIC KEY-----

  1. The text is copy of PuTTY User Manual or was inspired by it.Back

Last modified: by 73.211.71.130