Contents
What is SSH Agent?
SSH Agent is a program that stores your SSH private keys in memory and manages authentication without requiring you to enter your passphrase every time you use SSH. It provides a secure way to use SSH keys without repeatedly typing passwords or storing keys unprotected.
Why Use SSH Agent?
- Convenience: You don’t have to enter your passphrase each time you connect to a server.
- Security: Your private key is never exposed on disk after it’s added to the agent.
- Multiple Sessions: You can use the same SSH key across multiple connections without re-entering the passphrase.
How to Use SSH Agent
Step 1: Check if SSH Agent is Running
Before adding a key, verify that the SSH Agent is running with:
ps aux | grep ssh-agent
If it’s not running, start it using:
eval "$(ssh-agent -s)"
Step 2: Add Your SSH Key to the Agent
To add your SSH private key to the agent, use:
ssh-add ~/.ssh/id_rsa
If your key has a different name (e.g., id_ed25519
), adjust the command accordingly:
ssh-add ~/.ssh/id_ed25519
You will be prompted to enter your passphrase (if you set one).
Step 3: Verify the Key is Added
Check which keys are currently loaded in the agent:
ssh-add -l
This should display a fingerprint of your key.
Step 4: Use SSH with the Agent
Now, when you connect to a server using SSH, the agent will automatically provide authentication:
ssh user@yourserver.com
You won’t need to enter the passphrase again during your session.
Persisting SSH Agent Across Sessions
By default, the SSH Agent process does not persist across logouts or reboots. You can make it persist by adding the following to your ~/.bashrc
or ~/.zshrc
file:
if [ -z "$SSH_AUTH_SOCK" ]; then
eval "$(ssh-agent -s)"
fi
Conclusion
SSH Agent simplifies SSH key management by caching credentials securely. By following these steps, you can efficiently use SSH without entering your passphrase repeatedly. This is especially useful for developers and system administrators who frequently access remote systems.
0 Comments