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 "email@example.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 - start the ssh-agent in the background ### $ 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 ...
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 firstname.lastname@example.org # OR ... $ ssh -vT email@example.com # If youre using Github Enterprise ...
Warning: Permanently added the RSA host key for IP address ‘18.104.22.168’ 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.