Skip to content

ssh-add Linux Command Guide

The Linux ssh-add command is used to add private keys to the SSH authentication agent, allowing secure and convenient access to remote servers without entering passwords repeatedly. This command eliminates the need to re-enter private key passphrases every time an SSH connection is made, improving efficiency and security in managing SSH keys. By using ssh-add, users can easily add, list, and remove keys from the authentication agent, streamlining the SSH key management process.

ssh-add Syntax:

Terminal window
ssh-add [options] [file]

Options:

OptionDescription
-lLists fingerprints of all identities
-LPrints public key for all identities
-E hashSpecifies the hash algorithm for keys
-KLoads the default keys from macOS keychain
-kPrompts for passphrase and adds key
-qSuppresses all warnings and errors
-sSaves the passphrase in the keychain
-t lifetimeSets default cache lifetime in seconds
-xLocks the agent with a passphrase
-XUnlocks the agent
-cEnables confirmation for use of keys
-dDeletes the specified identities
-e pkcs11Lists keys served by the pkcs11
-s reader slotAdds a smartcard key
-DDeletes all identities
-U smartcardRemoves all smartcard keys
-uRemoves all identities from the agent

Parameters:

ParameterDescription
fileSpecifies an alternative to the default file path

ssh-add Command Samples:

Add a specific private key to the SSH agent

Terminal window
ssh-add ~/.ssh/id_rsa

This command adds the private key “id_rsa” to the SSH agent.

Add all private keys in the default directory to the SSH agent

Terminal window
ssh-add

This command automatically adds all private keys found in the default directory (~/.ssh) to the SSH agent.

Specify an identity file to add to the SSH agent

Terminal window
ssh-add -i /path/to/private_key.pem

The command adds a specific private key file (“private_key.pem”) to the SSH agent.

Display currently added identities in the SSH agent

Terminal window
ssh-add -l

This command lists the fingerprints of all identities currently represented by the SSH agent.

Remove a specific key from the SSH agent

Terminal window
ssh-add -d /path/to/private_key

This command removes a specific private key from the SSH agent.

Remove all identities from the SSH agent

Terminal window
ssh-add -D

This command removes all identities from the SSH agent.

Add a key without using a passphrase

Terminal window
ssh-add -K ~/.ssh/private_key

This command adds a private key to the SSH agent without prompting for a passphrase.

ssh-add FAQ:

How do I add a specific SSH key using ssh-add in Linux?

To add a specific SSH key using ssh-add in Linux, use the following command:

Terminal window
ssh-add ~/.ssh/id_rsa

How do I list the keys currently added to the SSH agent with ssh-add in Linux?

To list the keys currently added to the SSH agent with ssh-add in Linux, use the following command:

Terminal window
ssh-add -l

How do I remove all added keys from the SSH agent using ssh-add in Linux?

To remove all added keys from the SSH agent using ssh-add in Linux, use the following command:

Terminal window
ssh-add -D

How do I set a specific lifetime for an added SSH key with ssh-add in Linux?

To set a specific lifetime for an added SSH key with ssh-add in Linux, use the following command:

Terminal window
ssh-add -t 3600 ~/.ssh/id_rsa

How do I display verbose output when adding an SSH key with ssh-add in Linux?

To display verbose output when adding an SSH key with ssh-add in Linux, use the following command:

Terminal window
ssh-add -v ~/.ssh/id_rsa

How do I add a passphrase-protected SSH key without prompting for its passphrase every time with ssh-add in Linux?

To add a passphrase-protected SSH key without prompting for its passphrase every time with ssh-add in Linux, use the following command:

Terminal window
ssh-add -K ~/.ssh/id_rsa

Applications of the ssh-add command

  • To add private keys to the SSH authentication agent
  • To manage multiple private keys for SSH connections
  • To enable seamless and secure authentication without password prompts
  • To easily authenticate to remote servers with SSH keys