Search code examples
windowssshcmdssh-keys

Rename SSH Key Agent that was already added


I added 2 ssh key using ssh-keygen command, one for personal and one for client. Running ssh-add -l will display all the agent added via ssh-add and this is what I get.

enter image description here

I wonder if we can rename the existing ssh key email so it is much clearer. As much as possible I do not want to delete the existing, just want to update its email.

I didn't know before that you can configure ssh key generation like this

ssh-keygen -t rsa -b 4096 -C "personal@email.com" -f id_rsa
ssh-keygen -t rsa -b 4096 -C "client@email.com" -f id_rsa-client

Which could give me a list of ssh agent with different email when running ssh-add -l

4096 SHA256:XXXXXX personal@email.com (RSA)
4096 SHA256:XXXXXX client@email.com (RSA)

Solution

  • Those aren't actually emails, just "comments". You can update the keyfile with

    ssh-keygen -c -C "personal@email.com" -f .ssh\id_rsa
    

    Then remove and re-add the identity with (WARNING: The command below will delete ALL keys)

    ssh-add -D
    ssh-add
    

    Your key would still work with the sites and servers you've registered the public key to.