SSH-ADD(1)

๐Ÿ’… SSH-ADD(1) โ€” General Commands Manual ๐ŸŽ€

okay so bestie, welcome to ssh-add(1), from the General Commands Manual โ€” yes that one, the OpenSSH one, the icon herself. she's about to make your keys make sense โœจ


๐ŸŒธ NAME ๐ŸŒธ

ssh-add โ€” adds private key identities to the OpenSSH authentication agent. that's it, that's the whole job, and she does it flawlessly ๐Ÿ’…


โœจ SYNOPSIS โœจ

ssh-add [-CcDdKkLlNqvXx] [-E fingerprint_hash] [-H hostkey_file]
        [-h destination_constraint] [-S provider] [-t life] [file ...]
ssh-add -s pkcs11 [-Cv] [certificate ...]
ssh-add -e pkcs11
ssh-add -T pubkey ...

like, four whole modes, pick your fighter ๐Ÿซถ


๐Ÿ’– DESCRIPTION ๐Ÿ’–

so ssh-add adds private key identities to the authentication agent, ssh-agent(1). no cap.

when you run it with no arguments at all, she goes and adds these files for you, unprompted, main character energy:

  • ~/.ssh/id_rsa
  • ~/.ssh/id_ecdsa
  • ~/.ssh/id_ecdsa_sk
  • ~/.ssh/id_ed25519
  • ~/.ssh/id_ed25519_sk

and after loading a private key, ssh-add will also try to load corresponding certificate information from the filename you get by appending -cert.pub to the name of the private key file. love a girl who checks for the bonus content ๐Ÿ’– alternative file names can be given on the command line, obviously.

if any file requires a passphrase, ssh-add asks you for it. the passphrase is read from the user's tty. and here's the cute part โ€” ssh-add retries the last passphrase if multiple identity files are given. she remembers. she's thoughtful like that ๐ŸŽ€

the authentication agent must be running and the SSH_AUTH_SOCK environment variable must contain the name of its socket for ssh-add to work. non-negotiable, that's the whole vibe check.

the options are as follows:


๐Ÿฆ‹ OPTIONS ๐Ÿฆ‹

  • -C โ€” when loading keys into or deleting keys from the agent, process certificates only and skip plain keys.
  • -c โ€” indicates that added identities should be subject to confirmation before being used for authentication. confirmation is performed by ssh-askpass(1). and listen โ€” successful confirmation is signaled by a zero exit status from ssh-askpass(1), not by text entered into the requester. that's the detail everyone gets wrong, iykyk.
  • -D โ€” deletes all identities from the agent. nuclear option bestie ๐Ÿ’€
  • -d โ€” instead of adding identities, removes identities from the agent. if ssh-add has been run with no arguments, the keys for the default identities and their corresponding certificates will be removed. otherwise, the argument list will be interpreted as a list of paths to public key files to specify keys and certificates to be removed from the agent. if no public key is found at a given path, ssh-add will append .pub and retry. and if the argument list consists of - then ssh-add will read public keys to be removed from standard input. icon behaviour fr.
  • -E fingerprint_hash โ€” specifies the hash algorithm used when displaying key fingerprints. valid options are: md5 and sha256. the default is sha256. as it should be ๐Ÿ’…
  • -e pkcs11 โ€” remove keys provided by the PKCS#11 shared library pkcs11.
  • -H hostkey_file โ€” specifies a known hosts file to look up hostkeys when using destination-constrained keys via the -h flag. this option may be specified multiple times to allow multiple files to be searched. if no files are specified, ssh-add will use the default ssh_config(5) known hosts files: ~/.ssh/known_hosts, ~/.ssh/known_hosts2, /etc/ssh/ssh_known_hosts, and /etc/ssh/ssh_known_hosts2.
  • -h destination_constraint โ€” when adding keys, constrain them to be usable only through specific hosts or to specific destinations. this one's a whole saga so buckle up ๐Ÿ“:

destination constraints of the form [user@]dest-hostname permit use of the key only from the origin host (the one running ssh-agent(1)) to the listed destination host, with optional user name.

constraints of the form src-hostname>[user@]dst-hostname allow a key available on a forwarded ssh-agent(1) to be used through a particular host (as specified by src-hostname) to authenticate to a further host, specified by dst-hostname.

multiple destination constraints may be added when loading keys. when attempting authentication with a key that has destination constraints, the whole connection path โ€” including ssh-agent(1) forwarding โ€” is tested against those constraints and each hop must be permitted for the attempt to succeed. for example, if a key is forwarded to a remote host, host-b, and is attempting authentication to another host, host-c, then the operation will be successful only if host-b was permitted from the origin host and the subsequent host-b>host-c hop is also permitted by destination constraints. literally the whole chain gets checked, no skipping steps.

hosts are identified by their host keys, and are looked up from known hosts files by ssh-add. wildcards patterns may be used for hostnames and certificate host keys are supported. by default, keys added by ssh-add are not destination constrained.

destination constraints were added in OpenSSH release 8.9. support in both the remote SSH client and server is required when using destination-constrained keys over a forwarded ssh-agent(1) channel.

it is also important to note that destination constraints can only be enforced by ssh-agent(1) when a key is used, or when it is forwarded by a cooperating ssh(1). specifically, it does not prevent an attacker with access to a remote SSH_AUTH_SOCK from forwarding it again and using it on a different host (but only to a permitted destination). read that twice, bestie ๐Ÿ˜ญ
  • -K โ€” load resident keys from a FIDO authenticator.
  • -k โ€” when loading keys into or deleting keys from the agent, process plain private keys only and skip certificates.
  • -L โ€” lists public key parameters of all identities currently represented by the agent.
  • -l โ€” lists fingerprints of all identities currently represented by the agent.
  • -N โ€” when adding certificates, by default ssh-add will request that the agent automatically delete the certificate shortly after the certificate's expiry date. this flag suppresses this behaviour and does not specify a lifetime for certificates added to an agent.
  • -q โ€” be quiet after a successful operation. she's humble sometimes ๐Ÿ™ˆ
  • -S provider โ€” specifies a path to a library that will be used when adding FIDO authenticator-hosted keys, overriding the default of using the internal USB HID support.
  • -s pkcs11 โ€” add keys provided by the PKCS#11 shared library pkcs11. certificate files may optionally be listed as command-line arguments. if these are present, then they will be loaded into the agent using any corresponding private keys loaded from the PKCS#11 token.
  • -T pubkey ... โ€” tests whether the private keys that correspond to the specified pubkey files are usable by performing sign and verify operations on each. a little vibe check, for your keys ๐Ÿ”ฅ
  • -t life โ€” set a maximum lifetime when adding identities to an agent. the lifetime may be specified in seconds or in a time format specified in sshd_config(5).
  • -v โ€” verbose mode. causes ssh-add to print debugging messages about its progress. this is helpful in debugging problems. multiple -v options increase the verbosity. the maximum is 3. three is the limit, don't push her ๐Ÿ’€
  • -X โ€” unlock the agent.
  • -x โ€” lock the agent with a password.

๐ŸŒˆ ENVIRONMENT ๐ŸŒˆ

DISPLAY, SSH_ASKPASS and SSH_ASKPASS_REQUIRE

if ssh-add needs a passphrase, it will read the passphrase from the current terminal if it was run from a terminal. but if ssh-add does not have a terminal associated with it but DISPLAY and SSH_ASKPASS are set, it will execute the program specified by SSH_ASKPASS (by default ssh-askpass) and open an X11 window to read the passphrase. this is particularly useful when calling ssh-add from a .xsession or related script. so extra, so helpful ๐Ÿงš

SSH_ASKPASS_REQUIRE allows further control over the use of an askpass program:

  • if this variable is set to never then ssh-add will never attempt to use one.
  • if it is set to prefer, then ssh-add will prefer to use the askpass program instead of the TTY when requesting passwords.
  • finally, if the variable is set to force, then the askpass program will be used for all passphrase input regardless of whether DISPLAY is set. no escape hatch, she's committed.

SSH_AUTH_SOCK

identifies the path of a Unix-domain socket used to communicate with the agent.

SSH_SK_PROVIDER

specifies a path to a library that will be used when loading any FIDO authenticator-hosted keys, overriding the default of using the built-in USB HID support.


๐ŸŽ€ FILES ๐ŸŽ€

  • ~/.ssh/id_ecdsa
  • ~/.ssh/id_ecdsa_sk
  • ~/.ssh/id_ed25519
  • ~/.ssh/id_ed25519_sk
  • ~/.ssh/id_rsa

contains the ECDSA, authenticator-hosted ECDSA, Ed25519, authenticator-hosted Ed25519 or RSA authentication identity of the user โœจ

identity files should not be readable by anyone but the user. note that ssh-add ignores identity files if they are accessible by others. your keys, your business, nobody else's, periodt ๐Ÿ’…

โญ EXIT STATUS โญ

  • exit status is 0 on success ๐ŸŽ‰
  • 1 if the specified command fails ๐Ÿ˜ญ
  • 2 if ssh-add is unable to contact the authentication agent ๐Ÿ’€

๐Ÿ’œ SEE ALSO ๐Ÿ’œ

ssh(1), ssh-agent(1), ssh-askpass(1), ssh-keygen(1), sshd(8)

the whole friend group, honestly ๐Ÿซถ


๐Ÿ‘‘ AUTHORS ๐Ÿ‘‘

OpenSSH is a derivative of the original and free ssh 1.2.12 release by Tatu Ylonen. Aaron Campbell, Bob Beck, Markus Friedl, Niels Provos, Theo de Raadt and Dug Song removed many bugs, re-added newer features and created OpenSSH. Markus Friedl contributed the support for SSH protocol versions 1.5 and 2.0. legends, every single one ๐Ÿ”ฅ


and that's the page, bestie ๐Ÿ’– this was the Debian build of the General Commands Manual, dated September 11, 2025 โ€” go forth and ssh-add responsibly, mwah ๐ŸŽ€โœจ

๐Ÿ“ฆ where this page comes from