Home > Network Management > ssh-add

ssh-add: Add SSH Keys to the Agent

The ssh-add command adds private keys (identities) to the OpenSSH authentication agent (ssh-agent). This allows for automatic authentication during SSH connections without repeatedly entering passwords or passphrases, thereby enhancing security and improving SSH usability.

Overview

ssh-add loads SSH private keys into memory for management by ssh-agent. Once a key is added, all SSH connections using that key are automatically authenticated.

Key Features

  • Adds SSH private keys to ssh-agent
  • Convenient usage by entering passphrase only once
  • Provides functionality to view and delete added keys
  • Supports PKCS#11 tokens

Key Options

Commonly used options with the ssh-add command.

Key Management

Generated command:

Try combining the commands.

Description:

`ssh-add` Executes the command.

Combine the above options to virtually execute commands with AI.

Usage Examples

Various examples of using the ssh-add command.

Add Default SSH Keys

ssh-add

Adds private keys located in the default path (e.g., ~/.ssh/id_rsa) to ssh-agent. You will be prompted for the passphrase if one exists.

Add a Specific SSH Key

ssh-add ~/.ssh/my_custom_key

Adds a private key from a specified path to ssh-agent.

View Currently Added Keys

ssh-add -l

Checks the public key fingerprints of all private keys currently loaded in ssh-agent.

Delete a Specific Key

ssh-add -d ~/.ssh/my_custom_key

Deletes a specified private key from ssh-agent.

Delete All Keys

ssh-add -D

Deletes all private keys loaded in ssh-agent.

Add Key with Lifetime (1 Hour)

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

Sets the added key to be automatically removed from ssh-agent after 1 hour (3600 seconds).

Tips & Considerations

Useful tips and points to consider when using ssh-add.

Check ssh-agent Status

Before using ssh-add, ensure that ssh-agent is running. It usually starts automatically at session login, but you might need to start it manually.

  • Check Command: pgrep ssh-agent
  • Start Command (Example): eval "$(ssh-agent -s)"

Security Considerations

Adding keys to ssh-agent eliminates the need to re-enter passphrases, which is convenient. However, it can increase security risks if someone gains physical access to your system. Keys without passphrases require particular caution.

Utilize Key Lifetime Limits

Using the -t option to limit the key's lifetime enhances security by automatically removing the key after a specified period. This is particularly useful on shared systems or for temporary tasks.


Same category commands