Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use ssh-add to remove identities (pem files) from the agent

I can add pem files to my SSH agent very easily using ssh-add, like so:

$ ssh-add /home/jsmith/keys/mytest.pem

But I can't seem to remove them:

$ ssh-add -d /home/jsmith/keys/mytest.pem
Bad key file /home/jsmith/keys/mytest.pem: No such file or directory

The pem file still exists though... I haven't moved or changed it in any way. Why am I having so much trouble removing this pem file from my SSH agent that I just added a moment ago? What's the correct way to do this?

I want to avoid using ssh-add -D (with a capital "D") because that would delete all of the identities from my SSH agent, and I only want to delete the one I've specified.

like image 606
Dasmowenator Avatar asked Aug 03 '19 01:08

Dasmowenator


People also ask

How do I remove an ssh-agent key?

Go to System --> Preferences --> Startup Applications , and unselect the " SSH Key Agent (Gnome Keyring SSH Agent) " box -- you'll need to scroll down to find it. You'll still get an ssh-agent , only now it will behave sanely: no keys autoloaded, you run ssh-add to add them, and if you want to delete keys, you can.

Do we need to add SSH key to ssh-agent?

If your private RSA key is not encrypted with a passphrase, then ssh-agent is not necessary. The ssh command would be an example of a client.


1 Answers

You have to use the public key for this. So first extract the public key and then remove it from the agent.

ssh-keygen -y -f /home/jsmith/keys/mytest.pem > /home/jsmith/keys/mytest.pub
ssh-add -d /home/jsmith/keys/mytest.pub

The man page mentions the "public" key as well: "if no public key is found at a given path, ssh-add will append .pub and retry".

like image 52
Tony Stark Avatar answered Sep 17 '22 10:09

Tony Stark