pubkey.but 19 KB

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