1

I just started using Git Bash today and I was trying to create a trial SSH key with git bash so I didn't put any passphrase for it because I thought that I could delete it later and create a new one. how do I remove/ delete this SSH key with no passphrase using Git Bash and how do I check that the SSH key I created is really gone?

I have tried $ rm -f ~/.ssh/id_rsa* but I'm not sure if it really worked.

3
  • If you know the location and filename, you can certainly delete it. This depends what tool you used to create it in the first place and what you did with the key afterwards. What is the output of ls ~/.ssh/?
    – Matt
    Commented Jul 17, 2021 at 6:58
  • I used Git Bash to generate the ssh key and I do see 3 files in the C:\Users\user\.ssh folder. I didn't do anything with it yet. I just want to remove it from my computer. the output of the ls ~/.ssh/ are the files in the folder I just mentioned @Matt
    – VinceG
    Commented Jul 17, 2021 at 7:04
  • While GitBash comes with Git-for-Windows, it's not part of Git. It's just that Git needs a POSIX shell to run at all, so people took bash-for-Windows and stuck it into the Git-for-Windows distributions. This means that the bash tag might be appropriate (and the ssh tag is) but git isn't.
    – torek
    Commented Jul 18, 2021 at 5:19

1 Answer 1

5

So you probably use ssh-keygen in GitBash. When you used this command, it asked for file where the key should be stored in. By default this is ~/.ssh/id_rsa. You need to delete the specified file (as defined while creating the key) and the associated public key (e.g. id_rsa.pub).

You can inspect the content of the 3 files you have in ~/.ssh with cat ~/.ssh/xyz:

  • If you see something like -----BEGIN RSA PRIVATE KEY-----, it is a private key.
  • If you see something like ssh-rsa ..., it is a public key.

Be careful not to delete something you might still need in the future.


Don't worry too much in case you cannot find the key anymore. Just generate a new key-pair and then update the public key in the places where you had it configured. According to your question you just started to use the old key today, therefore you should still know where this is required.

3
  • For anyone who is changing files (say, if you're migrating to ED25519, and you now have a second set of id_ed25519 files), these steps will work as intended. You should delete or move the old id_rsa files when you are done.
    – Chris
    Commented Dec 5, 2022 at 18:00
  • 1
    I don't know. I just feel I need to comment on this. Just straight to the point answer. No "check this here" thingy. Complete and precise instructions. Thanks man.
    – Uzi
    Commented Mar 7, 2023 at 17:49
  • I still get a warning that the deleted key is not accessible (although git successfully uses the new key). ssh-add -d is "refused" by the agent, ssh-add -l shows "no identities".
    – wortwart
    Commented Dec 11, 2023 at 10:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.