Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am new to ssh keys. Can anyone explain how the ssh-agent bash and ssh-add works?

Need to understand its internals in future.

share|improve this question
    
Have you tried the top Google hit for any of these terms? –  Daniel Beck May 16 '11 at 19:37
    
Yes, I did. I didn't get any useful information. My bad –  maneeshshetty May 16 '11 at 20:06

1 Answer 1

up vote 10 down vote accepted

An agent is a program that keeps your keys in memory so that you only need to unlock them once, instead of every time. ssh-agent does this for SSH keys.

The usual methods for starting ssh-agent are:

  • eval `ssh-agent` – this runs the agent in background, and sets the apropriate environment variables for the current shell instance.

    (ssh-agent, when started with no arguments, outputs commands to be interpreted by your shell.)

  • exec ssh-agent bash – starts a new instance of the bash shell, replacing the current one.

    (With one or more arguments, ssh-agent doesn't output anything, but starts the specified command: in this case, the bash shell, but technically it could be anything.)

    The second method is sometimes preferred, since it automatically kills ssh-agent when you close the terminal window. (When starting it with eval, the agent would remain running, but inaccessible.)

However, this only starts an empty agent. To actually make it useful, you need to use ssh-add, which unlocks your keys (usually ~/.ssh/id_*) and loads them into the agent, making them accessible to ssh or sftp connections.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.