How to Solve Permission Denied (Publickey) Error in Git
This article demonstrates the steps you can follow to solve the Permission denied (publickey)
error in Git. If you are a regular Git user, you may encounter such an error while cloning a remote repository.
In such a case, it simply means that the server has rejected your request. How do you solve it?
Set Up a Public/Private Key Pair Set in Git
Open your terminal and run the command below to access your .ssh
directory.
$ cd ~/.ssh && ssh-keygen
Copy one of the following commands based on your system and execute.
On Linux:
cat id_rsa.pub | xclip
On OS X:
cat id_rsa.pub | pbcopy
On Windows:
cat id_rsa.pub | pbcopycat id_rsa.pub | clip
And
cat id_rsa.pub | clip
Add Key to Account
Now you can add your key to your account. You can do this by making a few tweaks to your .config
file, as shown below.
$ git config --global user.name <Your-Name>
$ git config --global user.email <Your-Email>
The next steps are below if you have already generated a public/private key.
Check Private Key
The command below determines which private key corresponds with your local computer.
eval $(ssh-agent -s)
Run the command below to define the location of your keys.
ssh-add ~/.ssh/id_rsa
As we illustrated earlier, you can now configure your SSH key by editing the .config
file.
- Public keys, also called authorized keys, determine who can access a system.
- Private keys, also called identity keys, identify users and grant them access to a system.
In a nutshell, SSH keys are similar to passwords but are more secure since they are extremely hard to decrypt. If you get the Permission denied (publickey)
in Git, you need to configure the keys in the .config
file as discussed above.
John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.
LinkedInRelated Article - Git Error
- How to Fix: Git Is Not Recognized as an Internal or External Command Error
- How to Resolve Git Status Unmerged Paths
- Bower: ENOGIT Git Is Not Installed or Not in the PATH
- How to Fix Another Git Process Seems to Be Running in This Repository Error
- How to Fix Fatal: Origin Does Not Appear to Be a Git Repository Error in Git
- How to Fix Fatal: The Current Branch Master Has No Upstream Branch Error in Git