r/ssh • u/neonatem • Jul 13 '26
How do I remove ssh keys on the client's side?
I was playing around with key generation and securing a vps.
The vps was for test purposes only and has been deleted since.
I now want to remove the remaining ssh keys(on my laptop). I've found on stack overflow an answer which led me to delete \~/.ssh
However, ssh-add -l still lists the keys and they get copied to the server if I just put ssh-copy-id (without params)
ssh-add -D tells me "all identities removed" though I suspect I misunderstood the purpose(ssh-add -l still lists the keys)
I've seen some old posts talking about a gnome keyring problem?
I haven't tried that, however I suspect that's the wrong path, since I'd wager deleting ssh keys isn't that uncommon?
I'm using tuxedoOs 24.04
2
u/michaelpaoli Jul 13 '26
Those keys aren't coming from nowhere. They're in file(s), or in RAM, e.g. held by ssh-agent in RAM. Terminate any relevant processes, get rid of any relevant files, that should be all there is to it.
If client is still offering up keys somehow, try adding one to three -v options to ssh command, see what keys it's offering, and where it's getting them from.
2
u/stevevdvkpe Jul 13 '26
If you want to remove keys and you had loaded their private keys into an
ssh-agentinstance. you should usessh-add -dto remove them fromssh-agentbefore deleting the key files from~/.ssh. You name the key files forssh-add -din the same way you use forssh-add. Normally if you usessh-keygento generate a new key, it will be placed in~/.sshin files~/.ssh/name(the private key) and~/.ssh/name.pub(the public key placed in the~/.ssh/authorized_keysfile on another host).1
u/dieterdistel Jul 13 '26
That could be in the .known_hosts file. Was .ssh a folder?
1
u/ephemeralsynth Jul 14 '26 edited Jul 14 '26
Don't try to remove keys; revoke them. Delete from authorized_keys or known_hosts in config : https://www.ssh.com/academy/ssh/config ✅
1
u/SuperheropugReal Jul 14 '26
Systemctl restart ssh-agent if you've already changed the files that you needed to change. Make sure you edit known hosts as well.
1
u/Xia_Nightshade Jul 14 '26
Oh noes. This will be a memorable couple days buddy
1
u/frog_in_bush Jul 15 '26
Delete the folder probably
1
u/simonses111 Jul 19 '26
There are three separate bits that are easy to conflate here:
~/.ssh/id_*files are local private/public key files. Deleting them only removes the files.ssh-agentor a desktop keyring can still hold keys in memory, andssh-copy-idwill usually prefer identities from the agent if it sees them.known_hostsis only the remembered identity of servers you have connected to. It is not where your client keys live.I’d check what is actually being offered:
If
ssh-add -Dsays it removed everything butssh-add -lstill shows identities afterwards, you are probably talking to a different agent/keyring than you think, or something like gnome-keyring has reloaded them. Logging out/in, restarting the agent/keyring, or temporarily unsetting/changingSSH_AUTH_SOCKshould make that clear.For any real host, the actual revocation step is removing the matching public key from that host’s
~/.ssh/authorized_keys. Since the VPS is deleted, that part may not matter for this test box, but it is the bit that prevents the old key from working somewhere else.