pageant.but 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. \C{pageant} Using \i{Pageant} for authentication
  2. Pageant is an SSH \i{authentication agent}. It holds your \i{private key}s
  3. in memory, already decoded, so that you can use them often
  4. \I{passwordless login}without needing to type a \i{passphrase}.
  5. \H{pageant-start} Getting started with Pageant
  6. Before you run Pageant, you need to have a private key in \c{*.\i{PPK}}
  7. format. See \k{pubkey} to find out how to generate and use one.
  8. When you run Pageant, it will put an icon of a computer wearing a
  9. hat into the \ii{System tray}. It will then sit and do nothing, until you
  10. load a private key into it. (You may need to use Windows'
  11. \q{Show hidden icons} arrow to see the Pageant icon.)
  12. If you click the Pageant icon with the right mouse button, you will
  13. see a menu. Select \q{View Keys} from this menu. The Pageant main
  14. window will appear. (You can also bring this window up by
  15. double-clicking on the Pageant icon.)
  16. The Pageant window contains a list box. This shows the private keys
  17. Pageant is holding. When you start Pageant, it has no keys, so the
  18. list box will be empty. After you add one or more keys, they will
  19. show up in the list box.
  20. To add a key to Pageant, press the \q{Add Key} button. Pageant will
  21. bring up a file dialog, labelled \q{Select Private Key File}. Find
  22. your private key file in this dialog, and press \q{Open}.
  23. Pageant will now load the private key. If the key is protected by a
  24. passphrase, Pageant will ask you to type the passphrase. When the
  25. key has been loaded, it will appear in the list in the Pageant
  26. window.
  27. Now start PuTTY and open an SSH session to a site that accepts your
  28. key. PuTTY will notice that Pageant is running, retrieve the key
  29. automatically from Pageant, and use it to authenticate. You can now
  30. open as many PuTTY sessions as you like without having to type your
  31. passphrase again.
  32. (PuTTY can be configured not to try to use Pageant, but it will try
  33. by default. See \k{config-ssh-tryagent} and
  34. \k{using-cmdline-agentauth} for more information.)
  35. When you want to shut down Pageant, click the right button on the
  36. Pageant icon in the System tray, and select \q{Exit} from the menu.
  37. Closing the Pageant main window does \e{not} shut down Pageant.
  38. If you want Pageant to stay running but forget all the keys it has
  39. acquired, select \q{Remove All Keys} from the System tray menu.
  40. \H{pageant-mainwin} The Pageant main window
  41. The Pageant main window appears when you left-click on the Pageant
  42. system tray icon, or alternatively right-click and select \q{View
  43. Keys} from the menu. You can use it to keep track of what keys are
  44. currently loaded into Pageant, and to add new ones or remove the
  45. existing keys.
  46. \S{pageant-mainwin-keylist} The key list box
  47. The large list box in the Pageant main window lists the private keys
  48. that are currently loaded into Pageant. The list might look
  49. something like this:
  50. \c ssh-ed25519 SHA256:TddlQk20DVs4LRcAsIfDN9pInKpY06D+h4kSHwWAj4w
  51. \c ssh-rsa 2048 SHA256:8DFtyHm3kQihgy52nzX96qMcEVOq7/yJmmwQQhBWYFg
  52. For each key, the list box will tell you:
  53. \b The type of the key. Currently, this can be
  54. \c{ssh-rsa} (an RSA key for use with the SSH-2 protocol),
  55. \c{ssh-dss} (a DSA key for use with the SSH-2 protocol),
  56. \c{ecdsa-sha2-*} (an ECDSA key for use with the SSH-2 protocol),
  57. \c{ssh-ed25519} (an Ed25519 key for use with the SSH-2 protocol),
  58. \c{ssh-ed448} (an Ed448 key for use with the SSH-2 protocol),
  59. or \c{ssh1} (an RSA key for use with the old SSH-1 protocol).
  60. \b The size (in bits) of the key, for key types that come in different
  61. sizes.
  62. \b The \I{key fingerprint}fingerprint for the public key. This should be
  63. the same fingerprint given by PuTTYgen, and (hopefully) also the same
  64. fingerprint shown by remote utilities such as \i\c{ssh-keygen} when
  65. applied to your \c{authorized_keys} file.
  66. \lcont{
  67. By default this is shown in the \q{SHA256} format. You can change to the
  68. older \q{MD5} format (which looks like \c{aa:bb:cc:...}) with the
  69. \q{Fingerprint type} drop-down, but bear in mind that this format is
  70. less secure and should be avoided for comparison purposes where possible.
  71. }
  72. \b The comment attached to the key.
  73. \b The state of deferred decryption, if enabled for this key.
  74. See \k{pageant-deferred-decryption}.
  75. \S{pageant-mainwin-addkey} The \q{Add Key} button
  76. To add a key to Pageant by reading it out of a local disk file,
  77. press the \q{Add Key} button in the Pageant main window, or
  78. alternatively right-click on the Pageant icon in the system tray and
  79. select \q{Add Key} from there.
  80. Pageant will bring up a file dialog, labelled \q{Select Private Key
  81. File}. Find your private key file in this dialog, and press
  82. \q{Open}. If you want to add more than one key at once, you can
  83. select multiple files using Shift-click (to select several adjacent
  84. files) or Ctrl-click (to select non-adjacent files).
  85. Pageant will now load the private key(s). If a key is protected by a
  86. passphrase, Pageant will ask you to type the passphrase.
  87. (This is not the only way to add a private key to Pageant. You can
  88. also add one from a remote system by using agent forwarding; see
  89. \k{pageant-forward} for details.)
  90. \S{pageant-mainwin-remkey} The \q{Remove Key} button
  91. If you need to remove a key from Pageant, select that key in the
  92. list box, and press the \q{Remove Key} button. Pageant will remove
  93. the key from its memory.
  94. You can apply this to keys you added using the \q{Add Key} button,
  95. or to keys you added remotely using agent forwarding (see
  96. \k{pageant-forward}); it makes no difference.
  97. \H{pageant-cmdline} The Pageant command line
  98. Pageant can be made to do things automatically when it starts up, by
  99. \I{command-line arguments}specifying instructions on its command line.
  100. If you're starting Pageant from the Windows GUI, you can arrange this
  101. by editing the properties of the \i{Windows shortcut} that it was
  102. started from.
  103. If Pageant is already running, invoking it again with the options
  104. below causes actions to be performed with the existing instance, not a
  105. new one.
  106. \S{pageant-cmdline-loadkey} Making Pageant automatically load keys
  107. on startup
  108. Pageant can automatically load one or more private keys when it
  109. starts up, if you provide them on the Pageant command line. Your
  110. command line might then look like:
  111. \c C:\PuTTY\pageant.exe d:\main.ppk d:\secondary.ppk
  112. If the keys are stored encrypted, Pageant will request the
  113. passphrases on startup.
  114. If Pageant is already running, this syntax loads keys into the
  115. existing Pageant.
  116. You can specify the \cq{--encrypted} option to defer decryption of
  117. these keys; see \k{pageant-deferred-decryption}.
  118. \S{pageant-cmdline-command} Making Pageant run another program
  119. You can arrange for Pageant to start another program once it has
  120. initialised itself and loaded any keys specified on its command
  121. line. This program (perhaps a PuTTY, or a WinCVS making use of
  122. Plink, or whatever) will then be able to use the keys Pageant has
  123. loaded.
  124. You do this by specifying the \I{-c-pageant}\c{-c} option followed
  125. by the command, like this:
  126. \c C:\PuTTY\pageant.exe d:\main.ppk -c C:\PuTTY\putty.exe
  127. \S{pageant-cmdline-openssh} Integrating with Windows OpenSSH
  128. Windows's own port of OpenSSH uses the same mechanism as Pageant to
  129. talk to its SSH agent (Windows named pipes). This means that Windows
  130. OpenSSH can talk directly to Pageant, if it knows where to find
  131. Pageant's named pipe.
  132. When Pageant starts up, it can optionally write out a file containing
  133. an OpenSSH configuration directive that tells the Windows \c{ssh.exe}
  134. where to find Pageant. If you include this file from your Windows SSH
  135. configuration, then \c{ssh.exe} should automatically use Pageant as
  136. its agent, so that you can keep your keys in one place and have both
  137. SSH clients able to use them.
  138. The option is \c{--openssh-config}, and you follow it with a filename.
  139. To refer to this file from your main OpenSSH configuration, you can
  140. use the \cq{Include} directive. For example, you might run Pageant
  141. like this (with your own username substituted, of course):
  142. \c pageant --openssh-config C:\Users\Simon\.ssh\pageant.conf
  143. and then add a directive like this to your main \cq{.ssh\\config} file
  144. (assuming that lives in the same directory that you just put
  145. \cw{pageant.conf}):
  146. \c Include pageant.conf
  147. \s{Note}: this technique only works with \e{Windows's} port of
  148. OpenSSH, which lives at \cw{C:\\Windows\\System32\\OpenSSH\\ssh.exe}
  149. if you have it installed. (If not, it can be installed as a Windows
  150. optional feature, e.g., via Settings > Apps & features > Optional
  151. features > Add a feature > OpenSSH Client.)
  152. There are other versions of OpenSSH for Windows, notably the one that
  153. comes with Windows \cw{git}. Those will likely not work with the same
  154. configuration, because they tend to depend on Unix emulation layers
  155. like MinGW or MSys, so they won't speak Windows native pathname syntax
  156. or understand named pipes. The above instructions will only work with
  157. Windows's own version of OpenSSH.
  158. So, if you want to use Windows \cw{git} with an SSH key held in
  159. Pageant, you'll have to set the environment variable \cw{GIT_SSH}, to
  160. point at a different program. You could point it at
  161. \cw{c:\\Windows\\System32\\OpenSSH\\ssh.exe} once you've done this
  162. setup \dash but it's just as easy to point it at Plink!
  163. \S{pageant-cmdline-unix} Unix-domain sockets: integrating with WSL 1
  164. Pageant can listen on the WinSock implementation of \q{Unix-domain
  165. sockets}. These interoperate with the Unix-domain sockets found in the
  166. original Windows Subsystem for Linux (now known as WSL 1). So if you
  167. ask Pageant to listen on one of these, then your WSL 1 processes can
  168. talk directly to Pageant.
  169. To configure this, run Pageant with the option \c{--unix}, followed
  170. with a pathname. Then, in WSL 1, set the environment variable
  171. \cw{SSH_AUTH_SOCK} to point at the WSL translation of that pathname.
  172. For example, you might run
  173. \c pageant --unix C:\Users\Simon\.ssh\agent.sock
  174. and in WSL 1, set the environment variable
  175. \c SSH_AUTH_SOCK=/mnt/c/Users/Simon/.ssh/agent.sock
  176. Alternatively, you can add a line to your \cw{.ssh/config} file inside
  177. WSL that says
  178. \c IdentityAgent /mnt/c/Users/Simon/.ssh/agent.sock
  179. although doing it like that may mean that \cw{ssh-add} commands won't
  180. find the agent, even though \cw{ssh} itself will.
  181. \s{Security note}: Unix-domain sockets are protected against access by
  182. other users by the file protections on their containing directory. So
  183. if your Windows machine is multiuser, make sure you create the socket
  184. inside a directory that other users can't access at all. (In fact,
  185. that's a good idea on general principles.)
  186. \s{Compatibility note}: WSL 2 processes cannot talk to Pageant by this
  187. mechanism, because WSL 2's Unix-domain sockets are managed by a
  188. separate Linux kernel, and not by the same kernel that WinSock talks
  189. to.
  190. \S{pageant-cmdline-keylist} Starting with the key list visible
  191. Start Pageant with the \i\c{--keylist} option to show the main window
  192. as soon as it starts up.
  193. \S{pageant-cmdline-restrict-acl} Restricting the \i{Windows process ACL}
  194. Pageant supports the same \i\c{-restrict-acl} option as the other
  195. PuTTY utilities to lock down the Pageant process's access control;
  196. see \k{using-cmdline-restrict-acl} for why you might want to do this.
  197. By default, if Pageant is started with \c{-restrict-acl}, it won't
  198. pass this to any PuTTY sessions started from its System Tray submenu.
  199. Use \c{-restrict-putty-acl} to change this. (Again, see
  200. \k{using-cmdline-restrict-acl} for details.)
  201. \H{pageant-forward} Using \i{agent forwarding}
  202. Agent forwarding is a mechanism that allows applications on your SSH
  203. server machine to talk to the agent on your client machine.
  204. Note that at present, whether agent forwarding in SSH-2 is available
  205. depends on your server. Pageant's protocol is compatible with the
  206. \i{OpenSSH} server, but the \i\cw{ssh.com} server uses a different
  207. agent protocol, which PuTTY does not yet support.
  208. To enable agent forwarding, first start Pageant. Then set up a PuTTY
  209. SSH session in which \q{Allow agent forwarding} is enabled (see
  210. \k{config-ssh-agentfwd}). Open the session as normal. (Alternatively,
  211. you can use the \c{-A} command line option; see
  212. \k{using-cmdline-agent} for details.)
  213. If this has worked, your applications on the server should now have
  214. access to a Unix domain socket which the SSH server will forward
  215. back to PuTTY, and PuTTY will forward on to the agent. To check that
  216. this has actually happened, you can try this command on Unix server
  217. machines:
  218. \c unixbox:~$ echo $SSH_AUTH_SOCK
  219. \c /tmp/ssh-XXNP18Jz/agent.28794
  220. \c unixbox:~$
  221. If the result line comes up blank, agent forwarding has not been
  222. enabled at all.
  223. Now if you run \c{ssh} on the server and use it to connect through
  224. to another server that accepts one of the keys in Pageant, you
  225. should be able to log in without a password:
  226. \c unixbox:~$ ssh -v otherunixbox
  227. \c [...]
  228. \c debug: next auth method to try is publickey
  229. \c debug: userauth_pubkey_agent: trying agent key my-putty-key
  230. \c debug: ssh-userauth2 successful: method publickey
  231. \c [...]
  232. If you enable agent forwarding on \e{that} SSH connection as well
  233. (see the manual for your server-side SSH client to find out how to
  234. do this), your authentication keys will still be available on the
  235. next machine you connect to - two SSH connections away from where
  236. they're actually stored.
  237. In addition, if you have a private key on one of the SSH servers,
  238. you can send it all the way back to Pageant using the local
  239. \i\c{ssh-add} command:
  240. \c unixbox:~$ ssh-add ~/.ssh/id_rsa
  241. \c Need passphrase for /home/fred/.ssh/id_rsa
  242. \c Enter passphrase for /home/fred/.ssh/id_rsa:
  243. \c Identity added: /home/fred/.ssh/id_rsa (/home/simon/.ssh/id_rsa)
  244. \c unixbox:~$
  245. and then it's available to every machine that has agent forwarding
  246. available (not just the ones downstream of the place you added it).
  247. \H{pageant-deferred-decryption} Loading keys without decrypting them
  248. You can add keys to Pageant \e{without} decrypting them. The key
  249. file will be held in Pageant's memory still encrypted, and when a
  250. client program first tries to use the key, Pageant will display a
  251. dialog box prompting for the passphrase so that the key can be
  252. decrypted.
  253. This works the same way whether the key is used by an instance of
  254. PuTTY running locally, or a remote client connecting to Pageant
  255. through agent forwarding.
  256. To add a key to Pageant in this encrypted form, press the \q{Add Key
  257. (encrypted)} button in the Pageant main window, or alternatively
  258. right-click on the Pageant icon in the system tray and select \q{Add
  259. Key (encrypted)} from there. Pageant will bring up a file dialog, in
  260. just the same way as it would for the plain \q{Add Key} button. But it
  261. won't ask for a passphrase. Instead, the key will be listed in the
  262. main window with \q{(encrypted)} after it.
  263. To start Pageant up in the first place with encrypted keys loaded into
  264. it, you can use the \cq{--encrypted} option on the command line. For
  265. example:
  266. \c C:\PuTTY\pageant.exe --encrypted d:\main.ppk
  267. After a key has been decrypted for the first use, it remains
  268. decrypted, so that it can be used again. The main window will list
  269. the key with \q{(\i{re-encryptable})} after it. You can revert it
  270. to the previous state, where a passphrase is required, using the
  271. \q{\i{Re-encrypt}} button in the Pageant main window.
  272. You can also \q{re-encrypt} all keys that were added encrypted by
  273. choosing \q{Re-encrypt All Keys} from the System tray menu.
  274. (Note that this does \e{not} discard cleartext keys that were not
  275. previously added encrypted!)
  276. \s{CAUTION}: When Pageant displays a prompt to decrypt an
  277. already-loaded key, it cannot give keyboard focus to the prompt dialog
  278. box. As far as I know this is a deliberate defensive measure by
  279. Windows, against malicious software. So make sure you click in the
  280. prompt window before typing your passphrase, or else the passphrase
  281. might be sent to somewhere you didn't want to trust with it!
  282. \H{pageant-security} Security considerations
  283. \I{security risk}Using Pageant for public-key authentication gives you the
  284. convenience of being able to open multiple SSH sessions without
  285. having to type a passphrase every time, but also gives you the
  286. security benefit of never storing a decrypted private key on disk.
  287. Many people feel this is a good compromise between security and
  288. convenience.
  289. It \e{is} a compromise, however. Holding your decrypted private keys
  290. in Pageant is better than storing them in easy-to-find disk files,
  291. but still less secure than not storing them anywhere at all. This is
  292. for two reasons:
  293. \b Windows unfortunately provides no way to protect pieces of memory
  294. from being written to the system \i{swap file}. So if Pageant is holding
  295. your private keys for a long period of time, it's possible that
  296. decrypted private key data may be written to the system swap file,
  297. and an attacker who gained access to your hard disk later on might
  298. be able to recover that data. (However, if you stored an unencrypted
  299. key in a disk file they would \e{certainly} be able to recover it.)
  300. \b Although, like most modern operating systems, Windows prevents
  301. programs from accidentally accessing one another's memory space, it
  302. does allow programs to access one another's memory space
  303. deliberately, for special purposes such as debugging. This means
  304. that if you allow a virus, trojan, or other malicious program on to
  305. your Windows system while Pageant is running, it could access the
  306. memory of the Pageant process, extract your decrypted authentication
  307. keys, and send them back to its master.
  308. Similarly, use of agent \e{forwarding} is a security improvement on
  309. other methods of one-touch authentication, but not perfect. Holding
  310. your keys in Pageant on your Windows box has a security advantage
  311. over holding them on the remote server machine itself (either in an
  312. agent or just unencrypted on disk), because if the server machine
  313. ever sees your unencrypted private key then the sysadmin or anyone
  314. who cracks the machine can steal the keys and pretend to be you for
  315. as long as they want.
  316. However, the sysadmin of the server machine can always pretend to be
  317. you \e{on that machine}. So if you forward your agent to a server
  318. machine, then the sysadmin of that machine can access the forwarded
  319. agent connection and request signatures from any of your private keys,
  320. and can therefore log in to other machines as you. They can only do
  321. this to a limited extent - when the agent forwarding disappears they
  322. lose the ability - but using Pageant doesn't actually \e{prevent} the
  323. sysadmin (or hackers) on the server from doing this.
  324. Therefore, if you don't trust the sysadmin of a server machine, you
  325. should \e{never} use agent forwarding to that machine. (Of course
  326. you also shouldn't store private keys on that machine, type
  327. passphrases into it, or log into other machines from it in any way
  328. at all; Pageant is hardly unique in this respect.)