OSDN Git Service

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