]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - doc/pubkey.but
first pass
[PuTTY.git] / doc / pubkey.but
1 \C{pubkey} Using public keys for SSH authentication
2
3 \H{pubkey-intro} \ii{Public key authentication} - an introduction
4
5 Public key authentication is an alternative means of identifying
6 yourself to a login server, instead of typing a password. It is more
7 secure and more flexible, but more difficult to set up.
8
9 In conventional password authentication, you prove you are who you
10 claim to be by proving that you know the correct password. The only
11 way to prove you know the password is to tell the server what you
12 think the password is. This means that if the server has been
13 hacked, or \i\e{spoofed} (see \k{gs-hostkey}), an attacker can learn
14 your password.
15
16 Public key authentication solves this problem. You generate a \i\e{key
17 pair}, consisting of a \i{public key} (which everybody is allowed to
18 know) and a \i{private key} (which you keep secret and do not give to
19 anybody). The private key is able to generate \i\e{signatures}.
20 A signature created using your private key cannot be forged by
21 anybody who does not have that key; but anybody who has your public
22 key can verify that a particular signature is genuine.
23
24 So you generate a key pair on your own computer, and you copy the
25 public key to the server. Then, when the server asks you to prove
26 who you are, PuTTY can generate a signature using your private key.
27 The server can verify that signature (since it has your public key)
28 and allow you to log in. Now if the server is hacked or spoofed, the
29 attacker does not gain your private key or password; they only gain
30 one signature. And signatures cannot be re-used, so they have gained
31 nothing.
32
33 There is a problem with this: if your private key is stored
34 unprotected on your own computer, then anybody who gains access to
35 \e{that} will be able to generate signatures as if they were you. So
36 they will be able to log in to your server under your account. For
37 this reason, your private key is usually \i\e{encrypted} when it is
38 stored on your local machine, using a \i{passphrase} of your choice. In
39 order to generate a signature, PuTTY must decrypt the key, so you
40 have to type your passphrase.
41
42 This can make public-key authentication less convenient than
43 password authentication: every time you log in to the server,
44 instead of typing a short password, you have to type a longer
45 passphrase. One solution to this is to use an \i\e{authentication
46 agent}, a separate program which holds decrypted private keys and
47 generates signatures on request. PuTTY's authentication agent is
48 called \i{Pageant}. When you begin a Windows session, you start Pageant
49 and load your private key into it (typing your passphrase once). For
50 the rest of your session, you can start PuTTY any number of times
51 and Pageant will automatically generate signatures without you
52 having to do anything. When you close your Windows session, Pageant
53 shuts down, without ever having stored your decrypted private key on
54 disk. Many people feel this is a good compromise between security
55 and convenience. See \k{pageant} for further details.
56
57 There is more than one \i{public-key algorithm} available. The most
58 common are \i{RSA} and \i{ECDSA}, but others exist, notably \i{DSA}
59 (otherwise known as DSS), the USA's federal Digital Signature Standard.
60 The key types supported by PuTTY are described in \k{puttygen-keytype}.
61
62 \H{pubkey-puttygen} Using \i{PuTTYgen}, the PuTTY key generator
63
64 \cfg{winhelp-topic}{puttygen.general}
65
66 PuTTYgen is a key generator. It \I{generating keys}generates pairs of
67 public and private keys to be used with PuTTY, PSCP, and Plink, as well
68 as the PuTTY authentication agent, Pageant (see \k{pageant}).  PuTTYgen
69 generates RSA, DSA, ECDSA, and Ed25519 keys.
70
71 When you run PuTTYgen you will see a window where you have two
72 choices: \q{Generate}, to generate a new public/private key pair, or
73 \q{Load} to load in an existing private key.
74
75 \S{puttygen-generating} Generating a new key
76
77 This is a general outline of the procedure for generating a new key
78 pair. The following sections describe the process in more detail.
79
80 \b First, you need to select which type of key you want to generate,
81 and also select the strength of the key. This is described in more
82 detail in \k{puttygen-keytype} and
83 \k{puttygen-strength}.
84
85 \b Then press the \q{Generate} button, to actually generate the key.
86 \K{puttygen-generate} describes this step.
87
88 \b Once you have generated the key, select a comment field
89 (\k{puttygen-comment}) and a passphrase (\k{puttygen-passphrase}).
90
91 \b Now you're ready to save the private key to disk; press the
92 \q{Save private key} button. (See \k{puttygen-savepriv}).
93
94 Your key pair is now ready for use. You may also want to copy the
95 public key to your server, either by copying it out of the \q{Public
96 key for pasting into authorized_keys file} box (see
97 \k{puttygen-pastekey}), or by using the \q{Save public key} button
98 (\k{puttygen-savepub}). However, you don't need to do this
99 immediately; if you want, you can load the private key back into
100 PuTTYgen later (see \k{puttygen-load}) and the public key will be
101 available for copying and pasting again.
102
103 \K{pubkey-gettingready} describes the typical process of configuring
104 PuTTY to attempt public-key authentication, and configuring your SSH
105 server to accept it.
106
107 \S{puttygen-keytype} Selecting the type of key
108
109 \cfg{winhelp-topic}{puttygen.keytype}
110
111 Before generating a key pair using PuTTYgen, you need to select
112 which type of key you need. PuTTYgen currently supports these types
113 of key:
114
115 \b An \i{RSA} key for use with the SSH-1 protocol.
116
117 \b An RSA key for use with the SSH-2 protocol.
118
119 \b A \i{DSA} key for use with the SSH-2 protocol.
120
121 \b An \i{ECDSA} (\i{elliptic curve} DSA) key for use with the
122 SSH-2 protocol.
123
124 \b An \i{Ed25519} key (another elliptic curve algorithm) for use
125 with the SSH-2 protocol.
126
127 The SSH-1 protocol only supports RSA keys; if you will be connecting
128 using the SSH-1 protocol, you must select the first key type or your
129 key will be completely useless.
130
131 The SSH-2 protocol supports more than one key type. The types
132 supported by PuTTY are RSA, DSA, ECDSA, and Ed25519.
133
134 \S{puttygen-strength} Selecting the size (strength) of the key
135
136 \cfg{winhelp-topic}{puttygen.bits}
137
138 The \q{Number of bits} input box allows you to choose the strength
139 of the key PuTTYgen will generate.
140
141 \b For RSA, 2048 bits should currently be sufficient for most purposes.
142
143 \#{FIXME: advice for DSA?}
144
145 \b For ECDSA, only 256, 384, and 521 bits are supported. (ECDSA offers
146 equivalent security to RSA with smaller key sizes.)
147
148 \b For Ed25519, the only valid size is 256 bits.
149
150 \S{puttygen-generate} The \q{Generate} button
151
152 \cfg{winhelp-topic}{puttygen.generate}
153
154 Once you have chosen the type of key you want, and the strength of
155 the key, press the \q{Generate} button and PuTTYgen will begin the
156 process of actually generating the key.
157
158 First, a progress bar will appear and PuTTYgen will ask you to move
159 the mouse around to generate randomness. Wave the mouse in circles
160 over the blank area in the PuTTYgen window, and the progress bar
161 will gradually fill up as PuTTYgen collects enough randomness. You
162 don't need to wave the mouse in particularly imaginative patterns
163 (although it can't hurt); PuTTYgen will collect enough randomness
164 just from the fine detail of \e{exactly} how far the mouse has moved
165 each time Windows samples its position.
166
167 When the progress bar reaches the end, PuTTYgen will begin creating
168 the key. The progress bar will reset to the start, and gradually
169 move up again to track the progress of the key generation. It will
170 not move evenly, and may occasionally slow down to a stop; this is
171 unfortunately unavoidable, because key generation is a random
172 process and it is impossible to reliably predict how long it will
173 take.
174
175 When the key generation is complete, a new set of controls will
176 appear in the window to indicate this.
177
178 \S{puttygen-fingerprint} The \q{\ii{Key fingerprint}} box
179
180 \cfg{winhelp-topic}{puttygen.fingerprint}
181
182 The \q{Key fingerprint} box shows you a fingerprint value for the
183 generated key. This is derived cryptographically from the \e{public}
184 key value, so it doesn't need to be kept secret; it is supposed to
185 be more manageable for human beings than the public key itself.
186
187 The fingerprint value is intended to be cryptographically secure, in
188 the sense that it is computationally infeasible for someone to
189 invent a second key with the same fingerprint, or to find a key with
190 a particular fingerprint. So some utilities, such as the Pageant key
191 list box (see \k{pageant-mainwin-keylist}) and the Unix \c{ssh-add}
192 utility, will list key fingerprints rather than the whole public key.
193
194 \S{puttygen-comment} Setting a comment for your key
195
196 \cfg{winhelp-topic}{puttygen.comment}
197
198 If you have more than one key and use them for different purposes,
199 you don't need to memorise the key fingerprints in order to tell
200 them apart. PuTTYgen allows you to enter a \e{comment} for your key,
201 which will be displayed whenever PuTTY or Pageant asks you for the
202 passphrase.
203
204 The default comment format, if you don't specify one, contains the
205 key type and the date of generation, such as \c{rsa-key-20011212}.
206 Another commonly used approach is to use your name and the name of
207 the computer the key will be used on, such as \c{simon@simons-pc}.
208
209 To alter the key comment, just type your comment text into the
210 \q{Key comment} box before saving the private key. If you want to
211 change the comment later, you can load the private key back into
212 PuTTYgen, change the comment, and save it again.
213
214 \S{puttygen-passphrase} Setting a \i{passphrase} for your key
215
216 \cfg{winhelp-topic}{puttygen.passphrase}
217
218 The \q{Key passphrase} and \q{Confirm passphrase} boxes allow you to
219 choose a passphrase for your key. The passphrase will be used to
220 \i{encrypt} the key on disk, so you will not be able to use the key
221 without first entering the passphrase.
222
223 When you save the key, PuTTYgen will check that the \q{Key passphrase}
224 and \q{Confirm passphrase} boxes both contain exactly the same
225 passphrase, and will refuse to save the key otherwise.
226
227 If you leave the passphrase fields blank, the key will be saved
228 unencrypted. You should \e{not} do this without good reason; if you
229 do, your private key file on disk will be all an attacker needs to
230 gain access to any machine configured to accept that key. If you
231 want to be able to \I{passwordless login}log in without having to
232 type a passphrase every time, you should consider using Pageant
233 (\k{pageant}) so that your decrypted key is only held in memory
234 rather than on disk.
235
236 Under special circumstances you may genuinely \e{need} to use a key
237 with no passphrase; for example, if you need to run an automated
238 batch script that needs to make an SSH connection, you can't be
239 there to type the passphrase. In this case we recommend you generate
240 a special key for each specific batch script (or whatever) that
241 needs one, and on the server side you should arrange that each key
242 is \e{restricted} so that it can only be used for that specific
243 purpose. The documentation for your SSH server should explain how to
244 do this (it will probably vary between servers).
245
246 Choosing a good passphrase is difficult. Just as you shouldn't use a
247 dictionary word as a password because it's easy for an attacker to
248 run through a whole dictionary, you should not use a song lyric,
249 quotation or other well-known sentence as a passphrase. \i{DiceWare}
250 (\W{http://www.diceware.com/}\cw{www.diceware.com}) recommends using
251 at least five words each generated randomly by rolling five dice,
252 which gives over 2^64 possible passphrases and is probably not a bad
253 scheme. If you want your passphrase to make grammatical sense, this
254 cuts down the possibilities a lot and you should use a longer one as
255 a result.
256
257 \e{Do not forget your passphrase}. There is no way to recover it.
258
259 \S{puttygen-savepriv} Saving your private key to a disk file
260
261 \cfg{winhelp-topic}{puttygen.savepriv}
262
263 Once you have generated a key, set a comment field and set a
264 passphrase, you are ready to save your private key to disk.
265
266 Press the \q{Save private key} button. PuTTYgen will put up a dialog
267 box asking you where to save the file. Select a directory, type in a
268 file name, and press \q{Save}.
269
270 This file is in PuTTY's native format (\c{*.\i{PPK}}); it is the one you
271 will need to tell PuTTY to use for authentication (see
272 \k{config-ssh-privkey}) or tell Pageant to load (see
273 \k{pageant-mainwin-addkey}).
274
275 \S{puttygen-savepub} Saving your public key to a disk file
276
277 \cfg{winhelp-topic}{puttygen.savepub}
278
279 RFC 4716 specifies a \I{SSH-2 public key format}standard format for
280 storing SSH-2 public keys on disk. Some SSH servers (such as
281 \i\cw{ssh.com}'s) require a public key in this format in order to accept
282 authentication with the corresponding private key. (Others, such as
283 OpenSSH, use a different format; see \k{puttygen-pastekey}.)
284
285 To save your public key in the SSH-2 standard format, press the
286 \q{Save public key} button in PuTTYgen. PuTTYgen will put up a
287 dialog box asking you where to save the file. Select a directory,
288 type in a file name, and press \q{Save}.
289
290 You will then probably want to copy the public key file to your SSH
291 server machine. See \k{pubkey-gettingready} for general instructions
292 on configuring public-key authentication once you have generated a
293 key.
294
295 If you use this option with an SSH-1 key, the file PuTTYgen saves
296 will contain exactly the same text that appears in the \q{Public key
297 for pasting} box. This is the only existing standard for SSH-1
298 public keys.
299
300 \S{puttygen-pastekey} \q{Public key for pasting into \i{authorized_keys
301 file}}
302
303 \cfg{winhelp-topic}{puttygen.pastekey}
304
305 All SSH-1 servers require your public key to be given to it in a
306 one-line format before it will accept authentication with your
307 private key. The \i{OpenSSH} server also requires this for SSH-2.
308
309 The \q{Public key for pasting into authorized_keys file} gives the
310 public-key data in the correct one-line format. Typically you will
311 want to select the entire contents of the box using the mouse, press
312 Ctrl+C to copy it to the clipboard, and then paste the data into a
313 PuTTY session which is already connected to the server.
314
315 See \k{pubkey-gettingready} for general instructions on configuring
316 public-key authentication once you have generated a key.
317
318 \S{puttygen-load} Reloading a private key
319
320 \cfg{winhelp-topic}{puttygen.load}
321
322 PuTTYgen allows you to load an existing private key file into
323 memory. If you do this, you can then change the passphrase and
324 comment before saving it again; you can also make extra copies of
325 the public key.
326
327 To load an existing key, press the \q{Load} button. PuTTYgen will
328 put up a dialog box where you can browse around the file system and
329 find your key file. Once you select the file, PuTTYgen will ask you
330 for a passphrase (if necessary) and will then display the key
331 details in the same way as if it had just generated the key.
332
333 If you use the Load command to load a foreign key format, it will
334 work, but you will see a message box warning you that the key you
335 have loaded is not a PuTTY native key. See \k{puttygen-conversions}
336 for information about importing foreign key formats.
337
338 \S{puttygen-conversions} Dealing with private keys in other formats
339
340 \cfg{winhelp-topic}{puttygen.conversions}
341
342 Most SSH-1 clients use a standard format for storing private keys on
343 disk. PuTTY uses this format as well; so if you have generated an
344 SSH-1 private key using OpenSSH or \cw{ssh.com}'s client, you can use
345 it with PuTTY, and vice versa.
346
347 However, SSH-2 private keys have no standard format. \I{OpenSSH private
348 key format}OpenSSH and \I{ssh.com private key format}\cw{ssh.com} have
349 different formats, and PuTTY's is different again.
350 So a key generated with one client cannot immediately be used with
351 another.
352
353 Using the \I{importing keys}\q{Import} command from the \q{Conversions}
354 menu, PuTTYgen can load SSH-2 private keys in OpenSSH's format and
355 \cw{ssh.com}'s format. Once you have loaded one of these key types, you
356 can then save it back out as a PuTTY-format key (\c{*.\i{PPK}}) so that
357 you can use it with the PuTTY suite. The passphrase will be unchanged by this
358 process (unless you deliberately change it). You may want to change
359 the key comment before you save the key, since OpenSSH's SSH-2 key
360 format contains no space for a comment and \cw{ssh.com}'s default
361 comment format is long and verbose.
362
363 PuTTYgen can also \i{export private keys} in OpenSSH format and in
364 \cw{ssh.com} format. To do so, select one of the \q{Export} options
365 from the \q{Conversions} menu. Exporting a key works exactly like
366 saving it (see \k{puttygen-savepriv}) - you need to have typed your
367 passphrase in beforehand, and you will be warned if you are about to
368 save a key without a passphrase.
369
370 For OpenSSH there are two options. Modern OpenSSH actually has two
371 formats it uses for storing private keys. \q{Export OpenSSH key}
372 will automatically choose the oldest format supported for the key
373 type, for maximum backward compatibility with older versions of
374 OpenSSH; for newer key types like Ed25519, it will use the newer
375 format as that is the only legal option. If you have some specific
376 reason for wanting to use OpenSSH's newer format even for RSA, DSA,
377 or ECDSA keys, you can choose \q{Export OpenSSH key (force new file
378 format)}.
379
380 Note that since only SSH-2 keys come in different formats, the export
381 options are not available if you have generated an SSH-1 key.
382
383 \H{pubkey-gettingready} Getting ready for public key authentication
384
385 Connect to your SSH server using PuTTY with the SSH protocol. When the
386 connection succeeds you will be prompted for your user name and
387 password to login. Once logged in, you must configure the server to
388 accept your public key for authentication:
389
390 \b If your server is using the SSH-1 protocol, you should change
391 into the \i\c{.ssh} directory and open the file \i\c{authorized_keys}
392 with your favourite editor. (You may have to create this file if
393 this is the first key you have put in it). Then switch to the
394 PuTTYgen window, select all of the text in the \q{Public key for
395 pasting into authorized_keys file} box (see \k{puttygen-pastekey}),
396 and copy it to the clipboard (\c{Ctrl+C}). Then, switch back to the
397 PuTTY window and insert the data into the open file, making sure it
398 ends up all on one line. Save the file.
399
400 \b If your server is \i{OpenSSH} and is using the SSH-2 protocol, you
401 should follow the same instructions, except that in earlier versions
402 of OpenSSH 2 the file might be called \c{authorized_keys2}. (In
403 modern versions the same \c{authorized_keys} file is used for both
404 SSH-1 and SSH-2 keys.)
405
406 \b If your server is \i\cw{ssh.com}'s product and is using SSH-2, you
407 need to save a \e{public} key file from PuTTYgen (see
408 \k{puttygen-savepub}), and copy that into the \i\c{.ssh2} directory on
409 the server. Then you should go into that \c{.ssh2} directory, and edit
410 (or create) a file called \c{authorization}. In this file you should
411 put a line like \c{Key mykey.pub}, with \c{mykey.pub} replaced by the
412 name of your key file.
413
414 \b For other SSH server software, you should refer to the manual for
415 that server.
416
417 You may also need to ensure that your home directory, your \c{.ssh}
418 directory, and any other files involved (such as
419 \c{authorized_keys}, \c{authorized_keys2} or \c{authorization}) are
420 not group-writable or world-writable. You can typically do this by
421 using a command such as
422
423 \c chmod go-w $HOME $HOME/.ssh $HOME/.ssh/authorized_keys
424
425 Your server should now be configured to accept authentication using
426 your private key. Now you need to configure PuTTY to \e{attempt}
427 authentication using your private key. You can do this in any of
428 three ways:
429
430 \b Select the private key in PuTTY's configuration. See
431 \k{config-ssh-privkey} for details.
432
433 \b Specify the key file on the command line with the \c{-i} option.
434 See \k{using-cmdline-identity} for details.
435
436 \b Load the private key into Pageant (see \k{pageant}). In this case
437 PuTTY will automatically try to use it for authentication if it can.