For Unix, what are ssh-agent and ssh-add, and how do I use them?

In Unix, ssh-agent is a background program that handles passwords for SSH private keys. The ssh-add command prompts the user for a private key password and adds it to the list maintained by ssh-agent. Once you add a password to ssh-agent, you will not be prompted for it when using SSH or scp to connect to hosts with your public key.

The public part of the key loaded into the agent must be put on the target system in ~/.ssh/authorized_keys; see How do I set up SSH public-key authentication to connect to a remote system?

To use ssh-agent and ssh-add, follow the steps below:

  1. At the Unix prompt, enter:
     eval `ssh-agent`

    Make sure you use the backquote (`), located under the tilde (~), rather than the single quote (').

  2. Enter the command:
     ssh-add
  3. Enter your private key password.
  4. When you log out, enter the command:
     kill $SSH_AGENT_PID
    To run this command automatically when you log out, place it in your .logout file (if you are using csh or tcsh) or your .bash_logout file (if you are using bash).
Note:
The versions of these programs for SSH2, ssh-agent2 and ssh-add2, are the same as outlined above. To use them, follow the instructions above, replacing all occurrences of ssh-agent with ssh-agent2, and ssh-add with ssh-add2. The SSH2 versions will only work if both your computer and the remote host are running SSH2.

At Indiana University, for personal or departmental Linux or Unix systems support, see At IU, how do I get support for Linux or Unix?

This is document aeww in the Knowledge Base.
Last modified on 2016-12-06 11:23:14.

  • Fill out this form to submit your issue to the UITS Support Center.
  • Please note that you must be affiliated with Indiana University to receive support.
  • All fields are required.

Please provide your IU email address. If you currently have a problem receiving email at your IU account, enter an alternate email address.

  • Fill out this form to submit your comment to the IU Knowledge Base.
  • If you are affiliated with Indiana University and need help with a computing problem, please use the I need help with a computing problem section above, or contact your campus Support Center.

Please provide your IU email address. If you currently have a problem receiving email at your IU account, enter an alternate email address.