How to fix - email@example.com permission denied (publickey). fatal could not read from remote repository
firstname.lastname@example.org: Permission denied (public key).fatal: Could not read from remote repository. - It means GitHub is rejecting your connection because -
- It is your private repo
- GitHub does not trust your computer because it does not have the public key of your computer.
And when you try to
clone the repo you get the following error message -
email@example.com: Permission denied (public key). 2fatal: Could not read from remote repository. 3 4Please make sure you have the correct access rights 5and the repository exists.
How to fix this issue?
Approach 1 : Using SSH keys
Benefits of this approach
- You do not need to supply you GitHub Username and password
- More secured
- The process of generating SSH keys is little troublesome.
- If you switch your laptop/desktop then you need re-generate the SSH keys again and perform the same steps onto your new laptop/desktop.
Approach 2 : Using git remote
This is one more approach in which you do not need to worry about SSH key generation.
You need following -
- GitHub repo URL with HTTPS (Ex - https://github.com/rahulwagh/example.git)
- Your GitHub Username
- Your GitHub Password
Run the following command to set
1git remote set-url origin https://github.com/rahulwagh/example.git
After that it will ask for your
password, supply your username and password.
Once you are authenticated then you can perform your Git operations.
Benefits of this approach
- You do not need to generate SSH keys
- You do not need to copy your SSH keys to GitHub accounts
- This approach can be used from any Laptop, Desktop. You only need to provide your GitHub credentials with this approach.
- The only drawback which I can see is you need to input your GitHub credentials everytime.
Step 1 - Create SSH key pair
One of the easiest ways for you to generate a key pair is by running
command prompt and type in the following
(Note - If you do not have ssh-keygen installed on the window then Click here.)
To keep the
ssh-keygen simple, do not enter any key name or passphrase.
1Generating public/private rsa key pair. 2Enter file in which to save the key (/Users/rahulwagh/.ssh/id_rsa): 3Enter passphrase (empty for no passphrase): 4Enter same passphrase again: 5Your identification has been saved in /Users/rahulwagh/.ssh/id_rsa. 6Your public key has been saved in /Users/rahulwagh/.ssh/id_rsa.pub. 7The key fingerprint is: 8SHA256:Okq3w+SesCGLQVToSBQru8RdUZtT2EIIrzH5MQ67DWA rahulwagh@local 9The key's randomart image is: 10+---[RSA 3072]----+ 11|.ooo..+oo. | 12| oo o..o+. | 13|=E = = +. | 14|*oo X o . | 15|.+ = o S | 16|o. + .. | 17|o ..+=+ | 18| o + *++ | 19|. . o.+. | 20+----[SHA256]-----+
Where to find the key pair
The file will be generated at - /Users/rahulwagh/.ssh/
Name of the file - id_rsa
(If you do not know how to generate ssh keys on Windows then follow the below steps otherwise you can directly jump to Step 2 - Adding SSH key to your GitHub account)
ssh-keygen on Windows 10
If you are working on a windows machine then you need to install the
Goto: Apps > Apps and Features > Manage Optional Features
Verify the list of the apps, if it already installed. If not then go at the top of the page then select
Add a Feature afterwords -
- OpenSSH Client : Locate
OpenSSH Client, then click
- OpenSSH Server : Locate
OpenSSH Server, then click
Install OpenSSH using PowerShell on Windows 10
If you like using Powershell then first make sure
OpenSSH features are available to install -
Copy and run the following command
1Get-WindowsCapability -Online | ? Name -like 'OpenSSH*' 2 3# This should return the following output: 4 5Name : OpenSSH.Client~~~~0.0.1.0 6State : NotPresent 7Name : OpenSSH.Server~~~~0.0.1.0 8State : NotPresent
After that install
server and client features using the following command -
1# Install the OpenSSH Client 2Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0 3 4# Install the OpenSSH Server 5Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0 6 7# Both of these should return the following output: 8` 9Path : 10Online : True 11RestartNeeded : False
1.2 Verify OpenSSH client is installed
- Goto settings panel
- Click on Optional Features and then look for OpenSSH client, if you can find the OpenSSH client which means you have installed it correctly.
1.3 Generate ssh keys on windows 10
- Next we need to run the
ssh-keygenand for that goto window’s command prompt and open it in administrator mode.
- In the command prompt type the following command
1Generating public/private rsa key pair. 2Enter file in which to save the key (C:\Users\rahulwagh/.ssh/id_rsa): 3Enter passphrase (empty for no passphrase): 4Enter same passphrase again: 5Your identification has been saved in C:\Users\rahulwagh/.ssh/id_rsa. 6Your public key has been saved in C:\Users\rahulwagh/.ssh/id_rsa.pub. 7The key fingerprint is: 8SHA256:Okq3w+SesCGLQVToSBQru8RdUZtT2EIIrzH5MQ67DWA rahulwagh@local 9The key's randomart image is: 10+---[RSA 3072]----+ 11|.ooo..+oo. | 12| oo o..o+. | 13|=E = = +. | 14|*oo X o . | 15|.+ = o S | 16|o. + .. | 17|o ..+=+ | 18| o + *++ | 19|. . o.+. | 20+----[SHA256]-----+ 21
1.4 Where to find the key pair
The file will be generated at - C:\Users\rahulwagh.ssh\id_rsa
Name of the file - id_rsa
Step 2 - Adding SSH key to your GitHub account
- Goto your GitHub Account -> Settings
- Then look for SSH and GPG keys under **Account Settings -> SSH and GPG keys **
- After that click on New SSH Key. Assign some meaningful name to your key
- To get the key goto to your command prompt and switch directory path
Windows - C:\Users\rahulwagh.ssh\id_rsa
Linux - /Users/rahulwagh/.ssh/
Run the following command
Copy the content of the key (do not copy first and the last line)
Paste the key inside your GitHub account
Now you can clone your GitHub repo and it will not complain about
firstname.lastname@example.org permission denied (publickey). fatal could not read from remote repository