Question

I created a Bitbucket/git the account. For some reason, I messed up the stuffs and failed to push up the repo. In a hurry I deleted my ~/.ssh directory.

So how to repair it?

Was it helpful?

Solution

Depends on what was in your .ssh dir.

Typically, the .ssh directory contains 3 kinds of file:

1) id_rsa / id_dsa / id*.pub - These are your private and public keys; your identity;
the key(s) that authenticate you to the remote SSH (git) server. If you lost the private
key, and don't have a backup then you are out of luck and will have to create a brand
new private/public keypair, and repeat the process you originally went through to
authorize your ssh/git client. In short, run ssh-keygen to generate new keys (today I recommend
you use 2048 bit length), and then proceed to Bitbucket to register your new public key
with the server.

2) If you also used authorized_keys, you will need to recreate that file or
find a backup. Those are only _public_ keys from other hosts that you use to login to
"this" host using key based authentication. If this is just a client machine, you likely
wont have an authorized_keys file.

3) known_hosts - The public server keys of SSH servers that you have accepted
in past sessions. It will be auto-created next time you connect to a
remote SSH server and accept a key forever. It is maintained by your SSH
clients, so don't worry about that file. You will, however, receive warnings as if
you've never connected to servers before until the file is fully repopulated.

So the important one is (1), your private key is not replaceable without a backup.

Bitkeeper: https://confluence.atlassian.com/display/BITBUCKET/Set+up+SSH+for+Git

In case the link ever goes bad, in short you use ssh-keygen to generate an RSA key (Google ssh-keygen), then you need to go to Bitkeeper Account settings and add in the id_rsa.pub (public key) portion.

Github is similar: https://help.github.com/articles/generating-ssh-keys

Lastly, always make a backup of your private key file on a thumb drive that you store in a physically secure place.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top