1SSH-KEYGEN(1) BSD General Commands Manual SSH-KEYGEN(1)
2
4 ssh-keygen — authentication key generation, management and conversion
5
7 ssh-keygen [-q] [-b bits] -t type [-N new_passphrase] [-C comment]
8 [-f output_keyfile]
9 ssh-keygen -p [-P old_passphrase] [-N new_passphrase] [-f keyfile]
10 ssh-keygen -i [-f input_keyfile]
11 ssh-keygen -e [-f input_keyfile]
12 ssh-keygen -y [-f input_keyfile]
13 ssh-keygen -c [-P passphrase] [-C comment] [-f keyfile]
14 ssh-keygen -l [-f input_keyfile]
15 ssh-keygen -B [-f input_keyfile]
16 ssh-keygen -D pkcs11
17 ssh-keygen -F hostname [-f known_hosts_file] [-l]
18 ssh-keygen -H [-f known_hosts_file]
19 ssh-keygen -R hostname [-f known_hosts_file]
20 ssh-keygen -r hostname [-f input_keyfile] [-g]
21 ssh-keygen -G output_file [-v] [-b bits] [-M memory] [-S start_point]
22 ssh-keygen -T output_file -f input_file [-v] [-a num_trials]
23 [-W generator]
24 ssh-keygen [-n] [-D smartcard]
25 ssh-keygen -s ca_key -I certificate_identity [-h] [-Z principals]
26 [-O option] [-V validity_interval] [-z serial_number] file ...
27 ssh-keygen -L [-f input_keyfile]
28
30 ssh-keygen generates, manages and converts authentication keys for
31 ssh(1). ssh-keygen can create RSA keys for use by SSH protocol version 1
32 and DSA, ECDSA or RSA keys for use by SSH protocol version 2. The type
33 of key to be generated is specified with the -t option. If invoked with‐
34 out any arguments, ssh-keygen will generate an RSA key for use in SSH
35 protocol 2 connections.
36
37 ssh-keygen is also used to generate groups for use in Diffie-Hellman
38 group exchange (DH-GEX). See the MODULI GENERATION section for details.
39
40 Normally each user wishing to use SSH with public key authentication runs
41 this once to create the authentication key in ~/.ssh/identity,
42 ~/.ssh/id_ecdsa, ~/.ssh/id_dsa or ~/.ssh/id_rsa. Additionally, the sys‐
43 tem administrator may use this to generate host keys, as seen in /etc/rc.
44
45 Normally this program generates the key and asks for a file in which to
46 store the private key. The public key is stored in a file with the same
47 name but “.pub” appended. The program also asks for a passphrase. The
48 passphrase may be empty to indicate no passphrase (host keys must have an
49 empty passphrase), or it may be a string of arbitrary length. A
50 passphrase is similar to a password, except it can be a phrase with a
51 series of words, punctuation, numbers, whitespace, or any string of char‐
52 acters you want. Good passphrases are 10-30 characters long, are not
53 simple sentences or otherwise easily guessable (English prose has only
54 1-2 bits of entropy per character, and provides very bad passphrases),
55 and contain a mix of upper and lowercase letters, numbers, and non-
56 alphanumeric characters. The passphrase can be changed later by using
57 the -p option.
58
59 There is no way to recover a lost passphrase. If the passphrase is lost
60 or forgotten, a new key must be generated and copied to the corresponding
61 public key to other machines.
62
63 For RSA1 keys, there is also a comment field in the key file that is only
64 for convenience to the user to help identify the key. The comment can
65 tell what the key is for, or whatever is useful. The comment is initial‐
66 ized to “user@host” when the key is created, but can be changed using the
67 -c option.
68
69 After a key is generated, instructions below detail where the keys should
70 be placed to be activated.
71
72 The options are as follows:
73
74 -a trials
75 Specifies the number of primality tests to perform when screening
76 DH-GEX candidates using the -T command.
77
78 -B Show the bubblebabble digest of specified private or public key
79 file.
80
81 -b bits
82 Specifies the number of bits in the key to create. For RSA keys,
83 the minimum size is 768 bits and the default is 2048 bits. Gen‐
84 erally, 2048 bits is considered sufficient. DSA keys must be
85 exactly 1024 bits as specified by FIPS 186-2.
86
87 -C comment
88 Provides a new comment.
89
90 -c Requests changing the comment in the private and public key
91 files. This operation is only supported for RSA1 keys. The pro‐
92 gram will prompt for the file containing the private keys, for
93 the passphrase if the key has one, and for the new comment.
94
95 -D pkcs11
96 Download the RSA public keys stored in the pkcs11 provider.
97
98 -e This option will read a private or public OpenSSH key file and
99 print the key in RFC 4716 SSH Public Key File Format to stdout.
100 This option allows exporting keys for use by several commercial
101 SSH implementations.
102
103 -F hostname
104 Search for the specified hostname in a known_hosts file, listing
105 any occurrences found. This option is useful to find hashed host
106 names or addresses and may also be used in conjunction with the
107 -H option to print found keys in a hashed format.
108
109 -f filename
110 Specifies the filename of the key file.
111
112 -G output_file
113 Generate candidate primes for DH-GEX. These primes must be
114 screened for safety (using the -T option) before use.
115
116 -g Use generic DNS format when printing fingerprint resource records
117 using the -r command.
118
119 -H Hash a known_hosts file. This replaces all hostnames and
120 addresses with hashed representations within the specified file;
121 the original content is moved to a file with a .old suffix.
122 These hashes may be used normally by ssh and sshd, but they do
123 not reveal identifying information should the file's contents be
124 disclosed. This option will not modify existing hashed hostnames
125 and is therefore safe to use on files that mix hashed and non-
126 hashed names.
127
128 -h When signing a key, create a host certificate instead of a user
129 certificate. Please see the CERTIFICATES section for details.
130
131 -I Specify the key identity when signing a public key. Please see
132 the CERTIFICATES section for details.
133
134 -i This option will read an unencrypted private (or public) key file
135 in SSH2-compatible format and print an OpenSSH compatible private
136 (or public) key to stdout. ssh-keygen also reads the RFC 4716
137 SSH Public Key File Format. This option allows importing keys
138 from several commercial SSH implementations.
139
140 -L Prints the contents of a certificate.
141
142 -l Show fingerprint of specified public key file. Private RSA1 keys
143 are also supported. For RSA and DSA keys ssh-keygen tries to
144 find the matching public key file and prints its fingerprint. If
145 combined with -v, an ASCII art representation of the key is sup‐
146 plied with the fingerprint.
147
148 -M memory
149 Specify the amount of memory to use (in megabytes) when generat‐
150 ing candidate moduli for DH-GEX.
151
152 -n Extract the public key from smartcard.
153
154 -N new_passphrase
155 Provides the new passphrase.
156
157 -Z principals
158 Specify one or more principals (user or host names) to be
159 included in a certificate when signing a key. Multiple princi‐
160 pals may be specified, separated by commas. Please see the
161 CERTIFICATES section for details.
162
163 -O option
164 Specify a certificate option when signing a key. This option may
165 be specified multiple times. Please see the CERTIFICATES section
166 for details. The options that are valid for user certificates
167 are:
168
169 no-x11-forwarding
170 Disable X11 forwarding. (permitted by default)
171
172 no-agent-forwarding
173 Disable ssh-agent(1) forwarding. (permitted by default)
174
175 no-port-forwarding
176 Disable port forwarding. (permitted by default)
177
178 no-pty Disable PTY allocation. (permitted by default)
179
180 no-user-rc
181 Disable execution of ~/.ssh/rc by sshd(8). (permitted by
182 default)
183
184 clear Clear all enabled permissions. This is useful for clear‐
185 ing the default set of permissions so permissions may be
186 added individually.
187
188 permit-x11-forwarding
189 Allows X11 forwarding.
190
191 permit-agent-forwarding
192 Allows ssh-agent(1) forwarding.
193
194 permit-port-forwarding
195 Allows port forwarding.
196
197 permit-pty
198 Allows PTY allocation.
199
200 permit-user-rc
201 Allows execution of ~/.ssh/rc by sshd(8).
202
203 force-command=command
204 Forces the execution of command instead of any shell or
205 command specified by the user when the certificate is
206 used for authentication.
207
208 source-address=address_list
209 Restrict the source addresses from which the certificate
210 is considered valid from. The address_list is a comma-
211 separated list of one or more address/netmask pairs in
212 CIDR format.
213
214 At present, no options are valid for host keys.
215
216 -P passphrase
217 Provides the (old) passphrase.
218
219 -p Requests changing the passphrase of a private key file instead of
220 creating a new private key. The program will prompt for the file
221 containing the private key, for the old passphrase, and twice for
222 the new passphrase.
223
224 -q Silence ssh-keygen. Used by /etc/rc when creating a new key.
225
226 -R hostname
227 Removes all keys belonging to hostname from a known_hosts file.
228 This option is useful to delete hashed hosts (see the -H option
229 above).
230
231 -r hostname
232 Print the SSHFP fingerprint resource record named hostname for
233 the specified public key file.
234
235 -S start
236 Specify start point (in hex) when generating candidate moduli for
237 DH-GEX.
238
239 -s ca_key
240 Certify (sign) a public key using the specified CA key. Please
241 see the CERTIFICATES section for details.
242
243 -T output_file
244 Test DH group exchange candidate primes (generated using the -G
245 option) for safety.
246
247 -t type
248 Specifies the type of key to create. The possible values are
249 “rsa1” for protocol version 1 and “dsa”, “ecdsa” or “rsa” for
250 protocol version 2.
251
252 -V validity_interval
253 Specify a validity interval when signing a certificate. A valid‐
254 ity interval may consist of a single time, indicating that the
255 certificate is valid beginning now and expiring at that time, or
256 may consist of two times separated by a colon to indicate an
257 explicit time interval. The start time may be specified as a
258 date in YYYYMMDD format, a time in YYYYMMDDHHMMSS format or a
259 relative time (to the current time) consisting of a minus sign
260 followed by a relative time in the format described in the TIME
261 FORMATS section of ssh_config(5). The end time may be specified
262 as a YYYYMMDD date, a YYYYMMDDHHMMSS time or a relative time
263 starting with a plus character.
264
265 For example: “+52w1d” (valid from now to 52 weeks and one day
266 from now), “-4w:+4w” (valid from four weeks ago to four weeks
267 from now), “20100101123000:20110101123000” (valid from 12:30 PM,
268 January 1st, 2010 to 12:30 PM, January 1st, 2011), “-1d:20110101”
269 (valid from yesterday to midnight, January 1st, 2011).
270
271 -v Verbose mode. Causes ssh-keygen to print debugging messages
272 about its progress. This is helpful for debugging moduli genera‐
273 tion. Multiple -v options increase the verbosity. The maximum
274 is 3.
275
276 -W generator
277 Specify desired generator when testing candidate moduli for DH-
278 GEX.
279
280 -y This option will read a private OpenSSH format file and print an
281 OpenSSH public key to stdout.
282
283 -z serial_number
284 Specifies a serial number to be embedded in the certificate to
285 distinguish this certificate from others from the same CA. The
286 default serial number is zero.
287
289 ssh-keygen may be used to generate groups for the Diffie-Hellman Group
290 Exchange (DH-GEX) protocol. Generating these groups is a two-step
291 process: first, candidate primes are generated using a fast, but memory
292 intensive process. These candidate primes are then tested for suitabil‐
293 ity (a CPU-intensive process).
294
295 Generation of primes is performed using the -G option. The desired
296 length of the primes may be specified by the -b option. For example:
297
298 # ssh-keygen -G moduli-2048.candidates -b 2048
299
300 By default, the search for primes begins at a random point in the desired
301 length range. This may be overridden using the -S option, which speci‐
302 fies a different start point (in hex).
303
304 Once a set of candidates have been generated, they must be tested for
305 suitability. This may be performed using the -T option. In this mode
306 ssh-keygen will read candidates from standard input (or a file specified
307 using the -f option). For example:
308
309 # ssh-keygen -T moduli-2048 -f moduli-2048.candidates
310
311 By default, each candidate will be subjected to 100 primality tests.
312 This may be overridden using the -a option. The DH generator value will
313 be chosen automatically for the prime under consideration. If a specific
314 generator is desired, it may be requested using the -W option. Valid
315 generator values are 2, 3, and 5.
316
317 Screened DH groups may be installed in /etc/ssh/moduli. It is important
318 that this file contains moduli of a range of bit lengths and that both
319 ends of a connection share common moduli.
320
322 ssh-keygen supports signing of keys to produce certificates that may be
323 used for user or host authentication. Certificates consist of a public
324 key, some identity information, zero or more principal (user or host)
325 names and a set of options that are signed by a Certification Authority
326 (CA) key. Clients or servers may then trust only the CA key and verify
327 its signature on a certificate rather than trusting many user/host keys.
328 Note that OpenSSH certificates are a different, and much simpler, format
329 to the X.509 certificates used in ssl(8).
330
331 ssh-keygen supports two types of certificates: user and host. User cer‐
332 tificates authenticate users to servers, whereas host certificates
333 authenticate server hosts to users. To generate a user certificate:
334
335 $ ssh-keygen -s /path/to/ca_key -I key_id /path/to/user_key.pub
336
337 The resultant certificate will be placed in /path/to/user_key-cert.pub.
338 A host certificate requires the -h option:
339
340 $ ssh-keygen -s /path/to/ca_key -I key_id -h /path/to/host_key.pub
341
342 The host certificate will be output to /path/to/host_key-cert.pub. In
343 both cases, key_id is a "key identifier" that is logged by the server
344 when the certificate is used for authentication.
345
346 Certificates may be limited to be valid for a set of principal
347 (user/host) names. By default, generated certificates are valid for all
348 users or hosts. To generate a certificate for a specified set of princi‐
349 pals:
350
351 $ ssh-keygen -s ca_key -I key_id -Z user1,user2 user_key.pub
352 $ ssh-keygen -s ca_key -I key_id -h -Z host.domain user_key.pub
353
354 Additional limitations on the validity and use of user certificates may
355 be specified through certificate options. A certificate option may dis‐
356 able features of the SSH session, may be valid only when presented from
357 particular source addresses or may force the use of a specific command.
358 For a list of valid certificate options, see the documentation for the -O
359 option above.
360
361 Finally, certificates may be defined with a validity lifetime. The -V
362 option allows specification of certificate start and end times. A cer‐
363 tificate that is presented at a time outside this range will not be con‐
364 sidered valid. By default, certificates have a maximum validity inter‐
365 val.
366
367 For certificates to be used for user or host authentication, the CA pub‐
368 lic key must be trusted by sshd(8) or ssh(1). Please refer to those man‐
369 ual pages for details.
370
372 ~/.ssh/identity
373 Contains the protocol version 1 RSA authentication identity of
374 the user. This file should not be readable by anyone but the
375 user. It is possible to specify a passphrase when generating the
376 key; that passphrase will be used to encrypt the private part of
377 this file using 3DES. This file is not automatically accessed by
378 ssh-keygen but it is offered as the default file for the private
379 key. ssh(1) will read this file when a login attempt is made.
380 ~/.ssh/identity.pub
381 Contains the protocol version 1 RSA public key for authentica‐
382 tion. The contents of this file should be added to
383 ~/.ssh/authorized_keys on all machines where the user wishes to
384 log in using RSA authentication. There is no need to keep the
385 contents of this file secret.
386
387 ~/.ssh/id_dsa
388 ~/.ssh/id_ecdsa
389 ~/.ssh/id_rsa
390 Contains the protocol version 2 DSA, ECDSA or RSA authentication
391 identity of the user. This file should not be readable by anyone
392 but the user. It is possible to specify a passphrase when gener‐
393 ating the key; that passphrase will be used to encrypt the pri‐
394 vate part of this file using 3DES. This file is not automati‐
395 cally accessed by ssh-keygen but it is offered as the default
396 file for the private key. ssh(1) will read this file when a
397 login attempt is made.
398
399 ~/.ssh/id_dsa.pub
400 ~/.ssh/id_ecdsa.pub
401 ~/.ssh/id_rsa.pub
402 Contains the protocol version 2 DSA, ECDSA or RSA public key for
403 authentication. The contents of this file should be added to
404 ~/.ssh/authorized_keys on all machines where the user wishes to
405 log in using public key authentication. There is no need to keep
406 the contents of this file secret.
407
408 /etc/ssh/moduli
409 Contains Diffie-Hellman groups used for DH-GEX. The file format
410 is described in moduli(5).
411
413 SSH_USE_STRONG_RNG
414 The reseeding of the OpenSSL random generator is usually done
415 from /dev/urandom. If the SSH_USE_STRONG_RNG environment vari‐
416 able is set to value other than 0 the OpenSSL random generator is
417 reseeded from /dev/random. The number of bytes read is defined
418 by the SSH_USE_STRONG_RNG value. Minimum is 14 bytes. This set‐
419 ting is not recommended on the computers without the hardware
420 random generator because insufficient entropy causes the connec‐
421 tion to be blocked until enough entropy is available.
422
424 ssh(1), ssh-add(1), ssh-agent(1), moduli(5), sshd(8)
425
426 The Secure Shell (SSH) Public Key File Format, RFC 4716, 2006.
427
429 OpenSSH is a derivative of the original and free ssh 1.2.12 release by
430 Tatu Ylonen. Aaron Campbell, Bob Beck, Markus Friedl, Niels Provos, Theo
431 de Raadt and Dug Song removed many bugs, re-added newer features and cre‐
432 ated OpenSSH. Markus Friedl contributed the support for SSH protocol
433 versions 1.5 and 2.0.
434
435BSD June 21, 2019 BSD