Git – Permission denied (publickey). How to fix?

I really like to mess up with my system, but I don’t panick when I do something wrong or end up breaking things. Fixing is fun. Sweating is fun.

octicons@1200x630

Well, a few days ago, I was setting up SSH Server, which I successfully did. I’m not a master of SSH, so I was exploring the commands in order to learn things.

If I remember correctly, for no reason, I typed this command –

$ ssh rishi@github.com

So yeah, I did. I don’t know why, but if you know what happens when you type this command, you’ll understand how silly it was. No regrets though.

Here is a rough and made up output –

The authenticity of host 'github.com (192.30.253.112)' can't be established.
ECDSA key fingerprint is SHA256:17INYs158/wFWvsIroDAm5YM.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com' (ECDSA) to the list of known hosts.

NOTE – rishi is not even my Github username!

Anyway, I forgot what I did and started exploring the SSH. I must say, it’s fun, and sometime very complicated, especially when you want to dive in it.

After a few hours, when I was done playing with it, I had to push some code to one of my old repository. Nothing fancy!

$ gith push -u origin master

This gave me an error, which was –

Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

It shouldn’t have happened. I got a little confused because a few hours ago everything was working fine, and then I realised what I’ve done. Just another silly mistake, but I knew how to quick fix it, so I just did –

Trying to be extra smart (Skip this part) –

$ git config --global user.name CodeDotJS
$ git config --global user.email myemail@gmail.com

Then –

 $ ssh-keygen -t rsa -b 4096 -C "myemail@gmail.com"
 $ eval "$(ssh-agent -s)"
 $ ssh-add ~/.ssh/id_rsa
 $ xclip -sel clip < ~/.ssh/id_rsa.pub

Added the new keys here and I was all set to push the futher commits.

So, what happened? 

  • Github wasn’t able to authenticate me.
    • Why?
      • My ssh keys were replaced with the useless ones.
  • Why so late SSHing?
    • I never learned SSH because I never felt its need. In the past, I’ve never even used. it, but I do know what it does. Anyway, due to remote works, I learned it. It was important and it’s definitely useful now.
  • Do I regret not learning it in past?
    • No. I don’t

 

I hope this helps. Thank you!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s