Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I had requested access to a git repository and it was granted after I gave my public and private keys.

( generated using the common method ssh-keygen -t rsa which gave me :

<user> @ <hostname> : ~/.ssh $ > ll
total 20K
-rw-------. 1 <user> 1.7K Mar 02 10:14 id_rsa
-rw-r--r--. 1 <user>  407 Mar 02 10:14 id_rsa.pub
-rw-r--r--. 1 <user> 1.3K Mar 01 14:25 known_hosts

)

However, I accidentally deleted my home directory. Fortunately, I had the backup of all my important files and so, it was not much of a hassle to recover those.

But, trying to clone the git repository again using the old public and private key, I could not. The git asked me for a password just like it would treat any non-authorised users.

So, I then had to request the access again using my current public and private keys.

Upon comparison, I found out that, the new keys are in fact different from the first ones.


So, my question is,

  1. Why does the public and private key change for a user in the same machine?
  2. In continuation of that question, why cant I use my old public and private key to access a repository when nothing else has changed?
  3. Will the keys change if I create them again using ssh-keygen -t rsa?

I can provide more info if needed.

share|improve this question
3  
"after I gave my public and private keys." As a rule you typically don't share the private key. –  Steven D Mar 25 at 6:11

1 Answer 1

up vote 5 down vote accepted
  1. A key pair is not tied to you as a user or your machine. Imagine having the keys to your house stolen. The keys aren't bound to you, anyone can use them to unlock your doors. In the exact same way, if I get my hands on your private key, I can use it to make changes to your Github repositories.
  2. If you wish to access your repositories using both your new keys and your old ones, you need to make sure the public keys for both key pairs are uploaded to Github. If Github only has your new key, it cannot authenticate you if you use your old key pair.
  3. Yes, the keys will change. That's sort of the point. Imagine buying a new lock for your door. If your old keys are the same as your new ones, it won't do you any good, esp. if you were changing the lock because someone stole your old key. If you were to have one of your ssh keys compromised, you could simply generate new keys & upload the corresponding public keys to Github after deleting the old ones. You can also have multiple key pairs. Generate as many as you wish and use them for different purposes. This is similar to having multiple keys for multiple locks in your house.

Also NEVER EVER give away your private keys. The private key is what is used to authenticate you as a person. If I get my hands on your private key, I can fake being you. Github can't tell the difference. No one but you needs to know what your private key is. If you have uploaded your private key somewhere, I recommend deleting it, generating a new pair & uploading the new public key just to be safe.

Read more about public key cryptography here.

share|improve this answer
1  
That was a clear and perfect answer @Prajjwal. +1 for that.Also, the git repository is maintained by my company. No issue of the keys falling into wrong hands. –  newbie Mar 25 at 6:38
    
TY :). If you've uploaded your private key somewhere, it's lying on some remote machine somewhere. You never know who could get their hands on it. Never give up your private key, ever. –  Prajjwal Mar 25 at 6:43
    
So, what if I recover my old keys in this case, can I use it to clone? I tried this approach and was not able to. –  newbie Mar 25 at 6:44
    
If and only if the public key from your old key pair has been uploaded to Github. If you deleted the old public key from your account, you'll have to re upload it. –  Prajjwal Mar 25 at 6:51
    
I collected the old key files I had used, moved it into ~/.ssh, set correct permissions to it, and tried cloning the repositories again. But, NO. I am not able to clone it successfully. ( NOTE : I have not yet asked my admin to give me access with the new keys even though I know I eventually will have to. I am trying to find a solution on my own before approaching him ) –  newbie Mar 25 at 9:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.