2

I accidentally did ssh-add -d, trying to remove a certain key but it removed all of them from my ssh-agent. Do I need to re-add my key from authorized_keys or will it automatically happen next time I login with ssh -i me@wherever?

I'm afraid to logout and then be locked out of the system.

I tried typing ssh-add /home/me/.ssh/authorized_keys but then it asks for a passphrase and I don't know what passphrase it's talking about.

8

ssh-add is the client part of ssh-agent, it has nothing to do with granting access to hosts (which is done by adding the public key (.pub) to ~/.ssh/authorized_hosts on the server side). ssh-agent is a program which you use on the client side, the server side only needs sshd.

By invoking ssh-add -d, you have cleared a cached key from ssh-agent such that you have to re-enter your SSH keyfile passphrase next time you ssh to a system. You won't lock yourself out by clearing this cache. Simply run ssh-add (or ssh-add ~/.ssh/id_rsa for a specific keyfile) to remember the keyfile passphrase again for this session.

The -i option of ssh is only necessary if your private key is located on a non-standard location. ssh -i ~/.ssh/id_rsa user@host is nearly equivalent to ssh user@host since ~/.ssh/id_rsa is one of the standard places where SSH looks for a keyfile.

The reason why ssh-add ~/.ssh/authorized_keys prompts for a password is because it did not recognize an unprotected key, and thus assumed a password-protected key. In fact, the file has an invalid format so no password will work here.

See also the manual page ssh-add(1).

0

You can either copy the contents of .ssh/id_rsa.pub (which is your public key) and add it to the end of .ssh/authorized_keys or use ssh-copy-id localhost to let SSH do the copying.

Note that your key doesn't need to be in .ssh/authorized_keys unless you plan on SSH'ing into that computer using that key.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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