Fixing git Permission denied (publickey) issue


First of all you have to create an SSH key, like so,

$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
This creates a new SSH key, using the provided email as a label.

After that you will get a message “Enter a file in which to save the key”. Give it the location and press Enter.

After that you will be ask for passphrase. It is optional and you can leave it as empty.

Now, copy the content of newly generated .pub file and paste it to
Github > Settings > SSH & GPG key

Add New SSH key

After adding to github. Go to terminal and type this

$ ssh -T git@github.com
This must output this line “Hi username! You’ve successfully authenticated, but GitHub does not provide shell access.”

If you get this message than you did this. If not perform this extra step

$ touch ~/.ssh/config
$ vim ~/.ssh/config

Add this code in file

Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/<your_file_name>

This is it. Run again
$ ssh -T git@github.com

Now, you are done.

LEAVE A COMMENT