Skip to content

Instantly share code, notes, and snippets.

@bilaliqbalr
Created August 3, 2017 10:20
Show Gist options
  • Save bilaliqbalr/ef61aba994bae039b662ed50dd852947 to your computer and use it in GitHub Desktop.
Save bilaliqbalr/ef61aba994bae039b662ed50dd852947 to your computer and use it in GitHub Desktop.
Fix 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.
@mkamranmalik72
Copy link

realy helpful for me its working i had the same issue

@nausmani
Copy link

This is just awesome. it works for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment