Add SSH Key to ssh-agent on Ubuntu Linux
This article provides a quick, step-by-step guide on how to add a
private SSH key to the ssh-agent on an Ubuntu Linux client.
By caching your private key in the agent, you can establish secure SSH
connections to remote servers without having to re-enter your key’s
passphrase every time.
Step 1: Start the ssh-agent
Before adding your private key, you must ensure that the
ssh-agent is running in the background. Open your terminal
and run the following command to start the agent:
eval "$(ssh-agent -s)"This command starts the agent and sets the necessary environment variables in your current shell session.
Step 2: Add Your Private SSH Key
Once the agent is running, use the ssh-add command
followed by the path to your private key file to add it to the
agent.
If you are using the default ED25519 key, run:
ssh-add ~/.ssh/id_ed25519If you are using a standard RSA key, run:
ssh-add ~/.ssh/id_rsaIf your private key is stored in a custom location, replace the path accordingly:
ssh-add /path/to/your/private_keyIf your key is protected by a passphrase, you will be prompted to
enter it once. The ssh-agent will then store the decrypted
key in memory.
Step 3: Verify the Added Key
To confirm that your private key has been successfully added to the
ssh-agent, list the currently loaded keys with the
following command:
ssh-add -lThis will display the fingerprint and the file path of all keys currently managed by the active agent.