If you encountered an error in Git that says “Permission denied (publickey)…” then you need to generate your SSH keys and add it to your Github account(https://github.mycompany.com/settings/ssh).

### STEP 1 - Generate a ssh key ###
$ ls -al ~/.ssh  # List all your local ssh keys
$ ssh-keygen -t rsa -b 4096 -C "myemail@mycompany.com"

Visit https://github.com/settings/ssh for more info.

Enter file in which to save the key (/c/Users/ADMIN/.ssh/id_rsa): /c/Users/ADMIN/.ssh/id_rsa_github
Enter passphrase (empty for no passphrase): press enter
Enter same passphrase again: press enter
Your identification has been saved in /c/Users/ADMIN/.ssh/id_rsa_github
Your public key has been saved in /c/Users/ADMIN/.ssh/id_rsa_github.pub.
The key fingerprint is: SHA256:XXX

### STEP 2 - If you've already created the ssh keys then you'll start the ssh-agent ###
$ eval $(ssh-agent) or exec ssh-agent bash (Linux)
### Next Add your SSH key to the ssh-agent
$ ssh-add /c/Users/ADMIN/.ssh/id_rsa_github

When executing the ssh-add command and you encountered an error like this:

Permissions 0644 for '~/.ssh/id_rsa_github' are too open.
It is recommended that your private key files are NOT accessible by others.
This private key will be ignored.

To fix it, we simply change the mode: chmod 600 -R ~/.ssh/*
NEXT.. We need to copy the contents of id_rsa_github.pub(not the id_rsa_github) and paste into your Github account SSH Keys.

NOTE: On most systems the default private keys (~/.ssh/id_rsa, ~/.ssh/id_dsa and ~/.ssh/identity) are automatically added to the SSH authentication agent. You shouldn’t need to run ssh-add path/to/key unless you override the file name when you generate a key.
When you set up an ssh key for github, if it’s not your default key, you will need to add a section to your ~/.ssh/config(create a file if doesn’t exist yet) something like this:

### (Optional) STEP 3 ###
$ vi ~/.ssh/config
# Then add this line in your config file
Host *github.com
    User git
    IdentityFile ~/.ssh/id_rsa_github

Host *github.mycompany.com  # If using the Github Enterprise
    User git
    IdentityFile ~/.ssh/id_rsa_mycompany

Next, Let’s test the connection

### STEP 4 ###
$ ssh -vT git@github.com # OR ...
$ ssh -vT git@github.mycompany.com # If youre using Github Enterprise

Warning: Permanently added the RSA host key for IP address ‘’ to the list of known hosts.
Hi sudogem! You’ve successfully authenticated, but GitHub does not provide shell access.
If the username in the message is yours, you’ve successfully set up your SSH key!

Finally it works!! You can start cloning any git repositories.

reference: https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/