You must have permission to access a Git repository before you can clone or modify a repository. If you try to clone or modify a repository which you do not have permission to access, you’ll encounter the “Please make sure you have the correct access rights” error.
This guide discusses the cause of and two potential solutions to this error. It walks you through the solutions step-by-step so you can learn how to use them.
Please make sure you have the correct access rights
To secure the code within a Git repository, the Git protocol restricts who can access a repository.
You must correctly specify the remote URL for a Git repository to access the project. If you specify the wrong URL, you will likely encounter an error about access rights because you’ll be trying to access a different project over which you may not have control.
You need to have privileges to access a repository if you want to clone or modify it. For instance, suppose you have a repository on GitHub. If that repository is private, only you should be able to access it. Git makes sure only you can access your repositories by asking you to pass a method of authentication, like a username and password check.
An Example Scenario
We’re going to clone the repository ck-git from GitHub. This repository is protected because it contains demo code that is not for the public’s use.
To clone this repository, we can use the git clone command:
git clone https://github.com/career-karma-tutorials/ck-git
This command retrieves all the code from our remote repository and saves it to our local machine. When we run this command, we encounter this error message:
Permission denied (publickey,password). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
Let’s read over this message. Git is telling us we do not have the correct access rights. This means we are either not authenticated or have not been granted access to a repository.
The most likely cause of this error is that you are not correctly authenticated. This may happen if you have changed your Git credentials or if the location of your repository has moved and a new one over which you have no access rights has replaced the old one.
The Solution
There are two potential solutions to this problem:
- Check your Git URL
- Ensure you have set up SSH public key and private key authentication correctly
Your first port of call should be to check your Git remote URL to make sure it is correct. In our case, we want to clone a project called career-karma-tutorials/ck-git from GitHub. Let’s check the clone command that we wrote earlier:
git clone https://github.com/career-karma-tutorials/ck-git
This command correctly points to our repository. If you try to clone the wrong repository, you may encounter the access rights error.
If this does not work, proceed to check for SSH authentication issues.
If you use SSH authentication to connect to a repository, make sure you have added your SSH key to your SSH agent. This will ensure that your SSH key is accessible to Git so that it can use the key to authenticate you with a repository.
To make sure that your SSH key has been added to your agent, you can run the ssh-add command:
ssh-add
This command will add your identity files to your SSH agent. Assuming the problem was that you had not set up SSH authentication on your local machine, this will solve the error.
A Solution for Existing Repositories
You may encounter the “Please make sure you have the correct access rights” error in an existing repository with which you are working. This may be caused by an SSH issue so you should check your SSH authentication setup if you use it before you proceed.
Assuming SSH authentication is not your issue, make sure you are pointing to the correct remote URL in your repository. You can do this using the git remote command:
git remote -v
The -v flag lets us see the URLs to which our repository is pointing:
origin https://github.com/career-karma-tutorials/ck-git (fetch) origin https://github.com/career-karma-tutorials/ck-git (push)
Suppose our repository moved to ck-git-tutorials and a new repository called ck-git was created over which we have no permission. We’ll have to update our remote pointer so we point to the correct repository.
We can do this using the git remote set-url command:
git remote set-url origin https://github.com/career-karma-tutorials/ck-git-tutorials
This will change our pointer to the ck-git-tutorials repository. Now, we can change our repository and push our code using the git push command.
Conclusion
The “Please make sure you have the correct access rights” error occurs if you do not have the right permissions to access a Git repository.
To solve this error, make sure you are referring to the correct remote URL and that you have set up SSH authentication correctly. If this error occurs in an existing repository, check to make sure your remote URLs are up-to-date.
About us: Career Karma is a platform designed to help job seekers find, research, and connect with job training programs to advance their careers. Learn about the CK publication.