You can authenticate yourself with a Git repository using either a Secure Shell (SSH) key or a password. If you use an SSH key and fail to configure that key correctly, you’ll encounter the “Permission denied (publickey). fatal: Could not read from remote repository” error.
In this guide, we discuss what this error means. We also discuss why you may encounter it and walk through an example so you can figure out how to solve this error.

Find Your Bootcamp Match
- Career Karma matches you with top tech bootcamps
- Access exclusive scholarships and prep courses
Select your interest
First name
Last name
Phone number
By continuing you agree to our Terms of Service and Privacy Policy, and you consent to receive offers and opportunities from Career Karma by telephone, text message, and email.
Permission denied (publickey). fatal: Could not read from remote repository
SSH keys let you authenticate with a Git repository without worrying about passwords. SSH is the same method of authentication that Linux servers use to allow remote access.
SSH keys rely on public-private key authentication. For this method of authentication to work, your Git server must be configured with a public key, and your local machine must have the corresponding private key.
Git clients like Atlassian and GitHub require that you upload your public key to their dashboards before you can use SSH authentication.
An Example Scenario
We’ve configured a local repository called ck-git. This repository contains one file: README.md.
We are going to link this repository to one on GitHub. To do this, we can use the git remote command:
git remote add origin git@github.com:career-karma-tutorials/ck-git.git
We have created a remote called “origin” to which we can push our code. To push our local repository to GitHub, we can use the git push command:
git push -u origin master
This command uploads our changes to the master branch on our “origin” remote server. Let’s see what happens when we run the command:
Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
We have encountered an error.
Solution #1: Check that your key is used
Before we explore any other solutions, we should make sure that our key is being used to make an SSH connection. We can do this by using the ssh-add command:
eval "$(ssh-agent -s)" ssh-add -l -E md5
The first command starts the SSH agent on your computer. The next command lists all of the SSH keys that are configured on your machine.
Now that you have this list of SSH keys, check to see if they match the one you’ve uploaded to GitHub, Bitbucket, or another version control system you use. If at least one of the keys on the list does not match, you need to add one of them to your version control system.
Solution #2: Adding an SSH key
You may encounter this error if you have not yet added an SSH key to your version control account. The way in which you add an SSH key to a Git repository varies depending on the version control system you use.
For GitHub, you can use the following steps:
- Note down your SSH key using the commands we discussed in Solution #1
- Open GitHub, click on your avatar on the top-right corner and click “Settings”
- Click “SSH and GPG keys” in the sidebar
- Add an SSH key to your account
To add an SSH key to your account, you must first have a key. You can generate one using the following commands:
ssh-keygen -t rsa -b 4096 -C "email@email.com" ssh-add -K ~/.ssh-/id_rsa
Substitute “id_rsa” for the name of your key if you changed it when you were prompted to choose a key name from the first command.
Then, run the following command to see your public key:
This will give you the string you need to upload into your version control system.
Cause #3: Using the wrong method of authentication
We’ve configured our repository to use an SSH URL:
git remote add origin git@github.com:career-karma-tutorials/ck-git.git
Using this URL means we must use SSH authorized key pairs to authenticate with our repository.
This is only possible if we have set up SSH authentication. If you want to configure your repository with HTTP, which lets you use a username and password to authenticate, you must use an HTTP URL:
git remote add origin https://github.com/career-karma-tutorials/ck-git
When we push our code to our remote server, we’ll be asked for our Git username and password. This will give us a chance to authenticate using HTTP instead of SSH.
Conclusion
The “Permission denied (publickey). fatal: Could not read from remote repository” error is caused by an issue with the way in which you authenticate with a Git repository.
To solve this error, make sure your key is being used on your Git account. If it is not, add your key to Git. If you do not have a public key and want to use one to authenticate with Git, you’ll need to create one.
You may want to opt to authenticate using HTTP if you do not want to use SSH. You can do this by using a HTTP URL as the remote URL for your repository.
-
Your Windows build number: Microsoft Windows [Version 10.0.18234.1000]
-
What you’re doing and what’s happening:
atlefren@atlsve-M4800:/mnt/d/code$ git —version
git version 2.7.4
atlefren@atlsve-M4800:/mnt/d/code$ git clone git@ssh.dev.azure.com:v3/path/to/repo
Cloning into ‘repo’…
path/to/repo is of course edited
…
remote: Found 319 objects to send. (11 ms)
Receiving objects: 100% (319/319), 186.51 KiB | 0 bytes/s, done.
Resolving deltas: 100% (132/132), done.
fatal: fsync error on ‘/mnt/d/code/repo/.git/objects/pack/tmp_idx_QfTqP5’: Permission denied
fatal: index-pack failed
atlefren@atlsve-M4800:/mnt/d/code$
- What’s wrong / what should be happening instead:
The permission denied part and the fact that repo is not cloned.
I get the same error when doing a git pull on an existing repo. However, this does not happen with all repos.
I recently edited the /etc/wsl.conf file to contain this:
[interop]
enabled=false # enable launch of Windows binaries; default is true
appendWindowsPath=false # append Windows path to $PATH variable; default is true
[automount]
options=case=off
the windows drives are mapped like so:
atlefren@atlsve-M4800:/mnt/d/code$ mount
rootfs on / type lxfs (rw,noatime)
root on /root type lxfs (rw,noatime)
home on /home type lxfs (rw,noatime)
data on /data type lxfs (rw,noatime)
cache on /cache type lxfs (rw,noatime)
mnt on /mnt type lxfs (rw,noatime)
none on /dev type tmpfs (rw,noatime,mode=755)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,noatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,noatime)
devpts on /dev/pts type devpts (rw,nosuid,noexec,noatime,gid=5,mode=620)
none on /run type tmpfs (rw,nosuid,noexec,noatime,mode=755)
none on /run/lock type tmpfs (rw,nosuid,nodev,noexec,noatime)
none on /run/shm type tmpfs (rw,nosuid,nodev,noatime)
none on /run/user type tmpfs (rw,nosuid,nodev,noexec,noatime,mode=755)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noatime)
C: on /mnt/c type drvfs (rw,relatime,uid=1000,gid=1000,case=off)
D: on /mnt/d type drvfs (rw,relatime,uid=1000,gid=1000,case=off)
Also: git clone of the same repo works fine /home/atlefren and works fine on Windows using git on windows. Guess it’s related to the mounting in some way. Problem appeared after updating Windows and adding the [interop]-part to /etc/wsl.conf
- Strace of the failing command, if applicable: https://gist.github.com/atlefren/ac570fe8b3f3e1cdd302964d917f7173
I know this question was asked before, but I already tried to use chmod or sudo and it’s still not working. So the thing is this:
I have bash on ubuntu on windows installed on my windows 10. I wrote my own shell in terminal but I did something wrong and deleted days of work by accident… So to be sure I started and wrote it again in codeblocks and just copied the c file in the directory so that i can see the file when i do the command ls.
The problem is when I try to do this:
gcc -o shell shell.c
I get
cc1: fatal error: shell.c: Permission denied
What can I do?
When I type ls -ld . shell.c shell I get:
drwxr-xr-x 0 Lightning Lightning 512 Jan 16 23:35 .
-rwxr-xr-x 1 root root 19576 Jan 16 23:35 shell
---------- 1 Lightning Lightning 17310 Jan 16 23:35 shell.c
And to clarify as a lot of you understand that I used sudo and that the shell file is the problem. It is not! Sudo solved my problem (I understand that it’s not the best solution, that’s why I’m trying to find another one), but I had the problem before I used sudo. And when I use the code:
gcc shell.c
I still get permission denied!
Solution:
cc1: fatal error: permission denied
Are you certain that this is the exact text of the error message? Could it have instead been this?
cc1: fatal error: shell.c: permission denied
Every single word counts in Unix-style error messages. The error message you said you got doesn’t refer to shell.c at all. It seems to be reporting a permissions problem affecting cc1, which is an internal component of the compiler, which is why the previous version of this answer said “your installation of GCC is broken”. But if that were your problem, you would not be able to compile anything, and you say you can compile other things besides shell.c.
The modified error message, on the other hand, is reporting a permissions problem detected by cc1 but affecting shell.c, which is consistent with the claim that only shell.c can’t be compiled, and is also consistent with your ls output:
---------- 1 Lightning Lightning 17310 Jan 16 23:35 shell.c
That leading string of dashes stands for access “mode” 000, which means “cannot be read, written, or executed by anyone, except root.” (One of root‘s many privileges is that it bypasses all access controls.)
If this is indeed your problem, running the commands
chmod 644 shell.c
sudo rm -f shell
from the directory containing shell.c should make a subsequent gcc shell.c -o shell work. These commands deserve a little explanation: chmod is the Unix command to change access permissions. chmod 644 sets the permissions to -rw-r--r-- (read and write by owning user, read-only by all others), which is almost always the right set of permissions for ordinary files. (You can also say chmod u=rw,go=r shell.c, but once you get a little practice with them, you will find the octal permissions easier to read and write!) It’s also necessary to delete shell, as root, because currently root owns that file and the compiler running as an ordinary user won’t be allowed to overwrite it.
The remaining question is: how on earth did your shell.c get its mode set to 000 in the first place? That is an extremely bizarre thing to have happen. My best guess would be that your “codeblocks” editor is a native Windows program instead of a Ubuntu-for-Windows program and it isn’t interacting properly with the nested Unix environment, but there are several other possibilities, and I don’t think I can help you any further.
EDIT: POSSIBLE FIX
In addition to the answers submitted, anyone with this error/same issue could also try running the command $ ssh-add ~/.ssh/id_rsa. This seems to work for me any time I need to get passed this error!
I’m very very new to using git and I’ve never deployed to gh-pages before, so I’m not sure what I’m doing wrong. I put in the homepage, dependencies, and scripts in my package.json file and when I run $ yarn run deploy everything works until the very end. It tells me it’s ready to be deployed to the page I want, and then it gives me this error:
Cloning into 'node_modules/gh-pages/.cache/git@github.com!emilybossiere!GrabBag.git'... Permission denied (publickey). fatal: Could not read from remote repository.
I’ve followed the GitHub instructions for this specific error, which led me to this page about checking for an SSH key. I’ve been successfully pushing to this repo the entire time I’ve worked on the application, so I know it’s authenticated and it works, but for some reason deployment doesn’t work.
This is my output when I run $ ssh -vT git@github.com
OpenSSH_7.4p1, LibreSSL 2.5.0
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 20: Applying options for *
debug1: Connecting to github.com [192.30.255.112] port 22.
debug1: Connection established.
debug1: identity file /Users/emilybo/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/emilybo/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/emilybo/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/emilybo/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/emilybo/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/emilybo/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/emilybo/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/emilybo/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
debug1: Remote protocol version 2.0, remote software version babeld-80573d3e
debug1: no match: babeld-80573d3e
debug1: Authenticating to github.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: rsa-sha2-512
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-rsa SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /Users/emilybo/.ssh/known_hosts:4
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-rsa,rsa-sha2-512,rsa-sha2-256,ssh-dss>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/emilybo/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: Authentication succeeded (publickey).
Authenticated to github.com ([192.30.255.112]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: pledge: network
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
Hi emilybossiere! You've successfully authenticated, but GitHub does not provide shell access.
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 2724, received 2236 bytes, in 0.1 seconds
Bytes per second: sent 31128.3, received 25551.7
debug1: Exit status 1
So it seems to connect just fine, so when I do $ eval "$(ssh-agent -s)" it returns > Agent pid 59566 as it should, but when I run $ ssh-add -l -E md5, it tells me The agent has no identities. Does this mean it’s not actually authenticated?
Also, step 2 of this page says something about automatically loading keys into the ssh agent, but I’ve never done this before and I’m not sure how to modify my ~/.ssh/config file but I don’t even seem to have one? How do I modify this file if it doesn’t exist? 
