Two common ways to clone a git repository are using SSH or HTTPS URL. When you clone the repository with SSH but do not have any SSH key in your git account, you will get the error “fatal: Could not read from remote repository”. In this tutorial, I will show you how to solve the problem by adding a new SSH key to your account or simply using an HTTPS URL.
What causes the error “fatal: Could not read from remote repository” in Git
Here I have an example of the error “Git fatal: Could not read from remote repository” when cloning a repository. You can run the command in your terminal on Linux/MacOS or your Command Prompt on Windows.
git clone [email protected]:dotnet/samples.git
Output:
Cloning into 'samples'...
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
The problem occurs because the URL “[email protected]:dotnet/samples.git” in the command is an SSH URL, but I haven’t setup any SSH key in my GitHub account, so the GitHub server denied my request to clone the repository.
How to solve the error
Solution 1: Adding an SSH key to your account
Before you can add an SSH key to your account, you need to create a new key on your machine. Follow these steps to create a new key and save it to the ssh agent.
- Step 1: Open your terminal if you are using Linux or MacOS. On Windows, open Git Bash by pressing the Windows button and typing Git Bash to search for the app.
- Step 2: Create an SSH key with ssh-keygen
ssh-keygen -t ed25519 -C "[email protected]"
You will be asked to enter the file to save the key and some other information. Press Enter to use default options.
- Step 3: Save the key to the ssh agent
ssh-add ~/.ssh/id_ed25519
After saving the key to the ssh agent, you can copy it and add it to your GitHub account.
- Step 1: Copy the key to your clipboard
You can show the generated key by the command
cat ~/.ssh/id_ed25519.pub
- Step 2: Log in to your GitHub account in the browser and go to Setting > SSH and GPG keys, then click on the “New SSH key” button, then enter the key and click “Add SSH key” to save.
After that, you can try to clone the repository again.
git clone [email protected]:dotnet/samples.git
Solution 2: Clone the repository by using the HTTPS URL
If you do not have a solid reason to use SSH, you can choose to use a simpler way to clone the repository by using the HTTPS URL.
git clone https://github.com/dotnet/samples.git
Summary
In this tutorial, I showed you how to solve the error “Git fatal: Could not read from remote repository”. You need to generate an SSH key on your machine and add it to your account. Or, if you don’t need to use SSH, you can clone the repository with the HTTPS URL.
Maybe you are interested:
- Error “src refspec master does not match any”
- Fatal: detected dubious ownership in repository
- How to delete folder in Gitlab repository

Hello, I’m Joseph Stanley. My major is IT and I want to share programming languages to you. If you have difficulty with JavaScript, TypeScript, C#, Python, C, C++, Java, let’s follow my articles. They are helpful for you.
Job: Developer
Name of the university: HUST
Major: IT
Programming Languages: JavaScript, TypeScript, C#, Python, C, C++, Java