ssh-keygen

authentication key generation, management and conversion

ssh-keygen [-q] [-b bits] -t type [-N new_passphrase] [-C comment] [-f output_keyfile]
ssh-keygen -p [-P old_passphrase] [-N new_passphrase] [-f keyfile]
ssh-keygen -i|e [-f keyfile]
(import|export)

ssh-keygen -y [-f keyfile] (yank private OpenSSH, output public key)
ssh-keygen -c [-P passphrase] [-C comment] [-f keyfile]

ssh-keygen -l [-f keyfile]
(list fingerprint)
ssh-keygen -B [-f keyfile]
(show bubblebabble)
ssh-keygen -F hostname [-f known_hosts_file] [-l]
(find host)

ssh-keygen -H [-f known_hosts_file]
(hash it)
ssh-keygen -R hostname [-f known_hosts_file]
(remove host)
ssh-keygen -D|U reader
download|Upload to reader
ssh-keygen -r hostname [-f input_keyfile] [-g]
(reveal fingerprint)

Generates, manages and converts authentication keys for ssh.

Creates RSA keys protocol version 1 and RSA or DSA keys for version 2 as specified with -t default RSA

Generates groups for use in Diffie-Hellman group exchange (DH-GEX).

Generates host keys for /etc/rc.

Users runs this to create their authentication key . With SSH keys, if someone gains access to your computer, they also gain access to every system that uses that key.
To add an extra layer of security, you can add a passphrase to your SSH key.
You can use ssh-agent to securely save your passphrase so you don't have to reenter it. Passphrase may be a string of arbitrary length, changed using -p. Similar to a password can be a phrase of words, punctuation, numbers, whitespace, or any string.

For RSA1 keys a comment field to the user to help identify the key, changed using -c .

-t RSA|DSA RSA vs DSA (when in doubt pick DSA IMHO ) Digital Signature Algorithm vs Ron Rivest, Adi Shamir, and Leonard Adleman.
-b bits number of bits in the key For RSA minimum 768 and default: 2048 bits. DSA 1024
-C comment RSA1
-cchange comment
-D reader
-U reader
Download the RSA public key to a smartcard in reader.
Upload an existing RSA private key into the smartcard in reader.
-e export key in RFC 4716 SSH Public Key File Format to stdout
-F hostname Find hostname in known_hosts Useful to find hashed host names or addresses and may also be used with -H
-H Hash known_hosts the original is moved to .old .
-R hostname Removes keys from known_hosts file useful to delete hashed hosts
-i Reads an unencrypted private key file or RFC4716 Public Key and outputs an OpenSSH to stdout.
-f filename key file.
-l list fingerprint of specified public key file.
With -v, an ASCII art representation of the key output:
-B file Show the bubblebabble digest
-p file Requests changing the passphrase of a private key file instead of creating a new private key. Prompts for the file containing the private key, for the old passphrase, and twice for the new passphrase.
-N new‑passphrase
-P current passphrase
-q quite (Used by /etc/rc when creating a new key.)
-r hostname reveal the SSHFP fingerprint resource record named hostname for the specified public key file. Default .ssh/id_rsa
-g Use generic DNS format when outputing fingerprint resource records using -r
-y read a private file and output public key to stdout.

 > ssh-keygen    
Generating public/private rsa key pair.
Enter file in which to save the key (/Volumes/DATA/dgerman/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Volumes/DATA/dgerman/.ssh/id_rsa.
Your public key has been saved in /Volumes/DATA/dgerman/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:oTvL+IaG8Hpe1D862lBRr7RMsqfEZtMaUymJVX/OLdY dgerman@smacpro
The key's randomart image is:
+---[RSA 2048]----+
|      ..o        |
|     o o +       |
|    . = * o .    |
|     o % + + o   |
|    . & S   = E  |
|.  . = X   . .   |
| . o..= o        |
|  +.==o+ .       |
|.+..o+*.         |
+----[SHA256]-----+

> ssh-keygen -B
Enter file in which the key is (/Volumes/DATA/dgerman/.ssh/id_rsa): 
2048 xugel-tymes-mopal-vyzoz-xxxxx-yyyyy-zzzzz-fucyc-kehip-nelef-vuxyx username@clienthost (RSA) 

> sh-keygen -l
Enter file in which the key is (/Volumes/DATA/dgerman/.ssh/id_rsa): 
2048 SHA256:oTvL+xxxxxxxxxx62yyyyyyyyyyEZtMaUymJVX/OLdY username@clienthost (RSA)/pre>

FILES

~/.ssh/identity version 1 RSA authentication identity of the user. Must be not be readable by by group or others. It is possible to specify a passphrase when generating the key which is used to encrypt the private part using 3DES. Not automatically accessed by ssh-keygen but is the default file for the private key. Read by ssh at login
~/.ssh/identity.pub version 1 RSA public key
. Add to ~/.ssh/authorized_keys
~/.ssh/id_dsa version 2 DSA authentication identity of the user. Must be not be readable by by group or others. It is possible to specify a passphrase when generating the key is used to encrypt the private part of this file using 3DES. Not automatically accessed by ssh-keygen but default is the file for the private key. Read by ssh at login made.
~/.ssh/id_dsa.pub version 2 DSA public key.
Add to ~/.ssh/authorized_keys
~/.ssh/id_rsa version 2 RSA authentication identity of the user. Must be not be readable by by group or others. A passphrase when generating the key used to encrypt the private part of this file using 3DES. Not automatically accessed by ssh-keygen default file for the private key. Read by ssh at login made.
~/.ssh/id_rsa.pub version 2 RSA public key . Added to ~/.ssh/authorized_keys
/etc/ssh/moduli for DH-GEX. See moduli

ssh-agent

ssh-agent [-c | -s] [-Dd] [-a bind_address] [-E fingerprint_hash] [-P pkcs11_whitelist] [-t life] [command [arg ...]] ssh-agent [-c | -s] -k Holds private keys used for public key authentication (RSA, DSA, ECDSA, Ed25519), started in the beginning of an X-session or a login session, and all other windows or programs are started as clients to it. Through use of environment variables the agent can be located and automatically used for authentication when logging in to other machines using ssh(1).

The agent initially does not have any private keys. Keys are added using ssh(1) (see AddKeysToAgent in ssh_config(5) for details) or ssh-add(1). Multiple identities may be stored in ssh-agent concurrently and ssh(1) will automatically use them if present. ssh-add(1) is also used to remove keys from ssh-agent and to query the keys that are held in one.
-a bind_address Bind the agent to the UNIX-domain socket bind_address. The default is $TMPDIR/ssh-XXXXXXXXXX/agent.ppid>.
-D Don't fork, Foreground mode.
-d debug mode.
-E md5|sha256 default sha256.
-k Kill the current agent (given by the $SSH_AGENT_PID
-P pkcs11_whitelist Specify a pattern-list of acceptable paths for PKCS#11 shared libraries that may be added using -s to ssh-add(1). default allow loading PKCS#11 libraries from ``/usr/lib/*,/usr/local/lib/*''. PKCS#11 libraries that do not match the whitelist will be refused. See PATTERNS in ssh_config(5) for a description of pattern-list syntax.
-c Generate C-shell commands on stdout. default if SHELL looks like it's a csh style of shell.
-s Generate Bourne shell commands on stdout. default if SHELL does not look like it's a csh style of shell.
-t life maximum lifetime of identities added to the agent. The lifetime may be specified in seconds or in a time format specified in sshd_config(5). A lifetime specified for an identity with ssh-add(1) overrides this value. default lifetime is forever.
If a command line is given, this is executed as a subprocess of the agent. When the command dies, so does the agent.

The agent is run in the user's local terminal. Authentication data need not be stored on any other machine, and authentication passphrases never go over the network. The connection to the agent is forwarded over SSH remote logins, and the user can thus use the privileges given by the identities anywhere in the netork in a secure way.