How to use ssh-agent for authentication on Linux / Unix

ssh-agent is a program that allows you to store your private SSH keys in memory, so that you don’t have to enter the passphrase every time you use them.

To use ssh-agent for authentication on Linux or Unix, you can follow these steps:

  1. Start by starting the ssh-agent program by running the following command:
eval "$(ssh-agent -s)"
  1. Next, add your private key to the ssh-agent by running the following command:
ssh-add ~/.ssh/id_rsa
  1. You will be prompted for your passphrase, enter it and your private key will be added to the ssh-agent.
  2. You can now use the ssh-agent to authenticate with a remote server using your private key without having to enter the passphrase again.
  3. To check which keys are currently managed by ssh-agent you can run the command ssh-add -l, it will show the fingerprints of the keys.
  4. To remove a key from the ssh-agent you can run the command ssh-add -d /path/to/key.
  5. To make the ssh-agent start automatically when you log in, you can add the eval "$(ssh-agent -s)" command to your shell profile file (e.g .bash_profile or .bashrc).
  6. To make it even more convenient, you can use a ssh-agent manager like keychain, ssh-agent forwarding, ssh-ident or ssh-agent-filter.

It’s important to note that the ssh-agent will only store the keys in memory for the current session. If you log out or reboot your computer, you will have to add the keys again to the ssh-agent. Also keep in mind that the ssh-agent is not a replacement for SSH key passphrases, it just makes it more convenient for you.

Leave a Comment