323

I am using TortoiseGit on Windows. When I am trying to Clone from the context menu of the standard Windows Explorer, I get this error:

Please make sure you have the correct access rights and the repository exists

More precisely, the snapshot of terminal is the following:

git.exe clone --progress -v "git@arobotdev:\git\AlfaRobot.git" "C:\Work\AlfaRobot"

Cloning into 'C:\Work\AlfaRobot'...
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,password).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

git did not exit cleanly (exit code 128) (21450 ms @ 19.09.2014 10:36:58)

What should I do to make git work properly ?

Alessio Cantarella
  • 5,077
  • 3
  • 27
  • 34
Alex
  • 3,231
  • 2
  • 11
  • 3
  • 1
    try generating ssh keygen and add – Raja Simon Sep 19 '14 at 07:03
  • Using Shell(or Git Bash in Windows) to create SSH Key: `$ ssh-keygen -t rsa -C "youremail@example.com"` – Belter Jan 05 '17 at 10:32
  • Had that error after changing the repos to git@github.com addresses for not having to type the password all the time. The real mistake that caused it was forgetting to add my public key on github. – dasWesen Jul 03 '19 at 21:49
  • in my case, i need to set config as in [here](https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#adding-your-ssh-key-to-the-ssh-agent) – Hadi KAR Jul 31 '21 at 03:09

35 Answers35

243

Your git URL might have changed. Change the URL in the local directory by using the following command:

for https protocol

git remote set-url origin https://github.com/username/repository.git

for ssh protocol

git remote set-url origin git@github.com:username/repository.git

There might be multiple causes for the issue:

  1. If the issue is with your ssh identity, see onkar-m18's answer here
  2. If ssh key is not added to hosting server, see lovekush-vishwakarma's answer here
PeterJames
  • 1,137
  • 1
  • 9
  • 17
Vishnu
  • 11,614
  • 6
  • 51
  • 90
  • 3
    Very common mistake was done by me. I copied using clip command `xclip -sel clip < ~/.ssh/id_rsa.pub`, but during pasting into github key input box, I removed last newline using backspace, which actually changed the public key. So, always copy & paste ssh public key as it is without removing last newline. – Amreesh Tyagi Oct 16 '19 at 16:09
  • 1
    It says No such remote 'origin' – Menaim Nov 17 '20 at 13:38
  • @Menaim You have to copy correct URL from bitbucket/github or any other provider. – Vishnu Dec 08 '20 at 07:19
  • what is the site url there? @Vishnu? – Mahdi Apr 21 '21 at 07:47
218

That problem might be having with your ssh-agent, your ssh key hasn't been added with ssh-agent.You have to apply following steps using your terminal:-

  1. $ eval "$(ssh-agent -s)"

    Agent pid 5867

  2. $ ssh-add <private-ssh-key-file-name> // eg. id_rsa (not .pub)

    Enter passphrase for /home/you/.ssh/id_rsa: [] Identity added: /home/you/.ssh/id_rsa (/home/you/.ssh/id_rsa)

starball
  • 20,030
  • 7
  • 43
  • 238
Onkar_M18
  • 2,601
  • 1
  • 13
  • 12
  • 37
    Still getting an error when cloning: `fatal: Could not read from remote repository.` – IgorGanapolsky Apr 08 '16 at 16:35
  • 3
    Thank it worked for me I have created different key than default id_rsa, so just have to do additionally in above command ssh-add -K ~/.ssh/id_rsa_other_project. – Nitesh Dec 15 '18 at 07:20
  • 1
    Yeah this won't fix any issue at all. Adding your identity to ssh only stops things asking for your cert password every time – DMcCallum83 Dec 19 '18 at 12:41
  • cheers. I had failed t run `brew update`. when i ran `ssh-add` before running the command, it worked. hope i dnt have t repeat this all the time. – nyxee Mar 21 '19 at 19:09
  • still get error "Host key verification failed. fatal: Could not read from remote repository." but adding known host fixed for me: https://stackoverflow.com/questions/15214977/cloning-git-repo-causes-error-host-key-verification-failed-fatal-the-remote/29380672#29380672 – rickvian May 16 '20 at 07:45
  • What to do if I have multiple repos? `ssh-add` uses an incorrect account by default – Gargo Jan 06 '21 at 15:44
  • 1
    Just doing ` eval "$(ssh-agent -s)"` solves my problem... for a while. Sjould I just add it to the commands ran while opening the shell? – Francesco Dondi May 20 '22 at 09:46
  • This does not solve the problem, you would need to run the commands every time you restart your shell. – L H Jun 07 '22 at 04:03
  • Adding `eval "$(ssh-agent -s)"` solves the issue. – Cesar Flores Jan 15 '23 at 15:38
  • I have to do this for each time I restart my laptop. Any other ways? – huykon225 May 08 '23 at 02:23
79

If it was working before and suddenly stopped working:

This issue can be caused because sometimes ssh-agent is not persistent across reboots. You should check if ssh-agent has your key added:

ssh-add -l -E md5

if you get the output like:

The agent has no identities.

it means ssh-agent has lost your key. In that case, you simply need to add the identity key again. Something like:

ssh-add ~/.ssh/git_rsa

The error should disappear now!

Community
  • 1
  • 1
shivam
  • 16,048
  • 3
  • 56
  • 71
  • 2
    This happened to me when I created another ssh for a different account, so I just add the missing `git_rsa` into the list – Dan Jul 13 '20 at 03:12
  • Thanks the `ssh-add -l -E md5` really listed `no identities` but instead of `ssh-add` i did a deprecated `ssh-add -A` which was the only way to stop it saying no identities and yes there is an updated way I think `--apple-use-keychain` and `--apple-load-keychain` – jamylak Oct 04 '22 at 03:08
77

Try to use HTTPS instead SSH while taking clone from GIT, use this Url for take clone , you can use Gitbase, Android Studio or any other tool for clone the branch. enter image description here

Lovekush Vishwakarma
  • 3,035
  • 23
  • 25
56

For me it was because of no SSH key on the machine. Check the SSH key locally:

$ cat ~/.ssh/id_rsa.pub

This is your SSH key. Add it to your SSH keys in the repository.
In gitlab go to

profile settings -> SSH Keys

and add the key

zx485
  • 28,498
  • 28
  • 50
  • 59
Jacek Góraj
  • 983
  • 1
  • 10
  • 16
  • 24
    I have added the key as you mentioned and still getting the access denied message. Please help – Jet Sep 05 '17 at 07:29
  • I had reinstalled operating system where my files were there. So just needed to generate ssh and add to github and problem solved. – muhammad tayyab Jun 28 '22 at 07:31
44

Github now uses a url scheme

git remote set-url origin https://github.com/username/repository.git

RyPope
  • 2,645
  • 27
  • 51
  • 2
    `fatal: No such remote 'origin'` . I have a repository on github and I initiated a git local repo on my machine with `git init` . – Jdeep Oct 28 '20 at 18:15
  • 2
    @NoahJ.Standerson You have to set remote "origin" on your local repository with `git remote add origin https://github.com/user/repo.git` - see https://docs.github.com/en/free-pro-team@latest/github/using-git/adding-a-remote – Deniz Genç Dec 07 '20 at 16:37
  • 2
    Support for password authentication was removed on August 13, 2021. Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information. – Andre DiCioccio Jan 21 '22 at 04:15
27
  1. run below command
open ~/.ssh

then manual delete "known_hosts" file

  1. run below command, generate new ssh-key
ssh-keygen -t rsa -C "your@email.com"

then two files : id_rsa and id_rsa.pub will generate in .ssh directory, copy the content in id_rsa.pub

  1. login github --> setting --> SSH and GPC keys --> add SSH keys --> paste the copied content in key

  2. run below command

ssh -T git@github.com

Ok, it works

Sam Dutton
  • 14,775
  • 6
  • 54
  • 64
HaitaoLiu
  • 271
  • 3
  • 2
23

If you're on a shared machine, using your own password or passwordless private key might be overkill. The safer option is an access token:

  1. Go to Settings, Developer Settings, Personal access tokens
  2. Generate new token.
  3. Note what the token is for.
  4. Grant repo access.
  5. Clone the repo:
$ git clone https://<token>@github.com/<user>/<repo>.git

If you've already cloned the repo, you could just modify your remote setting:

$ git remote set-url origin https://<token>@github.com/<user>/<repo>.git
$ git pull
Already up to date.
Cees Timmerman
  • 17,623
  • 11
  • 91
  • 124
  • 2
    Thank you so much, I face an issue to clone a repo inside a machine that need a vpn to work and this was the only way to connect to github. Thanks – palAlaa Sep 16 '21 at 05:33
  • 2
    This is the only thing that worked for me on a shared hosting. Thanks heaps! – terryeah Sep 01 '22 at 07:19
11

You are trying to clone the repository over ssh: git@arobotdev..., and your SSH keys are not properly set on server. There are multiple reasons to this:

  1. Your public key might not be saved in authorized_keys file of user git
  2. If 1 is not true the Your private key is not saved in .ssh/ folder of your HOMEDIR.
  3. Permissions are not properly set

If all 3 above are untrue then my only conclusion can be to try: git@arobotdev:AlfaRobot.git Assuming AlfaRobot.git is in HOMEDIR of git user and not inside a folder called git which resides in HOMEDIR of user git.

Mudassir Razvi
  • 1,783
  • 12
  • 33
10

I had this problem, and i discover that my system was with wrong dns address. Verify your network and test with

ssh -vvv git@bitbucket.org

And read the output messages. If you see "You can use git or hg to connect to Bitbucket." , everything is ok.

albert
  • 1,766
  • 1
  • 21
  • 24
8

I'm using Ubuntu

after reading many of answers, none of them can solve the problem, even if I already added SSH key to my git account, and try test it using ssh -T git@gitlab.com and it said Welcome <my username>, but it still kept telling me that I don't have access rights. Then I found the reason:

Normally if you're not root user, it will require you to run with sudo for every git command.

when running sudo git clone <SSH....> (for example). it will be executed under root permission, but accidentally when create SSH key I run it as normal user and I save the key in ~/.ssh/id_rsa, it resolves the absolute path /home/username/.ssh/id_rsa. And when doing sudo git clone ... it looks for SSH key in /root/.ssh/id_rsa

Why I can sure about this. To see where git looks for your SSH key. Run this command: sudo GIT_TRACE=1 GIT_SSH_COMMAND="ssh -vvv" git clone <your repository in SSH>. It will show you where it looks for your SSH key.

So the SOLUTION I suggest is:

Re-creating your SSH key (follow this instruction), BUT run sudo su at the very first step, then you'll should be fine.

Duc Trung Mai
  • 2,141
  • 1
  • 24
  • 23
  • 1
    The only solution, talking about sudo git clone searching SSH key in `/root/.ssh` folder. That was indeed my problem. Thanks! – p_duthoit Jun 18 '21 at 08:21
6
  1. The first thing you may want to confirm is the internet connection. Though, internet issues mostly will say that the repo cannot be accessed.

  2. Ensure you have set up ssh both locally and on your github. See how

  3. Ensure you are using the ssh git remote. If you had cloned the https, just set the url to the ssh url, with this git command git remote set-url origin git@github.com:your-username/your-repo-name.git

  4. If you have set up ssh properly but it just stopped working, do the following:

    • eval "$(ssh-agent -s)"
    • ssh-add

    If you are still having the issue, check to ensure that you have not deleted the ssh from your github. In a case where the ssh has been deleted from github, you can add it back. Use pbcopy < ~/.ssh/id_rsa.pub to copy the ssh key and then go to your github ssh setting and add it.

I will recommend you always use ssh. For most teams I've worked with, you can't access the repo (which are mostly private) except you use ssh. For a beginner, it may appear to be harder but later you'll find it quite easier and more secured.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Obinna Nnenanya
  • 1,530
  • 14
  • 15
5

The rsa.pub (i.e. public key generated), needs to be added on the github>> settings>>ssh keys page. Check that, you have not added this public key in the repository-settings >> deployment keys. If so, remove the entry from here and add to the first place mentioned.

Setup of the pub-private keys in detail.

It will work hence!

parasrish
  • 3,864
  • 26
  • 32
5

A wrongly configured ~/.ssh/config file can trigger this error.

GitHub's test command basically printed out the solution for me:

ssh -T git@github.com

/Users/myUser/.ssh/config: line 13: Bad configuration option: something-that-did-not-make-sense

Félix Paradis
  • 5,165
  • 6
  • 40
  • 49
3

add these lines to your .get/config file (thanks to @kovshenin answer Git Pull: Change Authentication) :

[credential]
    helper = wincred
Community
  • 1
  • 1
Khaled AbuShqear
  • 1,230
  • 14
  • 24
3

This can also happen if you are connecting to your git repository through a VPN. Make sure that you are connected to the VPN which is used to access the resources of your organization.

John Doe
  • 2,752
  • 5
  • 40
  • 58
3

I come across this error while uploading project to gitlab. I didn't clone from git but instead upload project. For pushing your code to gitlab you have two ways either using ssh or https. If you use https you have to enter username and password of gitlab account. For pushing you code to git you can use following one.

Pushing to Git for the first time

>$ cd
>$ mkdir .ssh;cd .ssh
>$ ssh-keygen -o -t rsa -b 4096 -C "email@example.com"

The -C parameter is optional, it provides a comment at the end of your key to distinguish it from others if you have multiple. This will create id_rsa (your private key) and id_rsa.pub (your public key). We pass our public key around and keep our private key — well, private. Gitlab’s User Settings is where you would then add your public key to your account, allowing us to finally push.

In your project location(Directory) use below command

git init

It Transform the current directory into a Git repository. This adds a .git subdirectory to the current directory and makes it possible to start recording revisions of the project.

Push Using https path

git push --set-upstream https://gitlab.com/Account_User_Name/Your_Project_Name.git master

Push Using ssh path

git push --set-upstream git@gitlab.com:Account_User_Name/Your_project_Name.git master

— set-upstream: tells git the path to origin. If Git has previously pushed on your current branch, it will remember where origin is

master: this is the name of the branch I want to push to when initializing

Gurjinder Singh
  • 9,221
  • 1
  • 66
  • 58
3

I just followed this explanation here

enter image description here

I tried eval and it works.

Then I tried ssh -T git@bitbucket.org

Then I clone again. Now everything runs smooth

Apit John Ismail
  • 2,047
  • 20
  • 19
2

Here is how I solve this issue. I was using Babun(mintty.exe) on Win7/10. When I have tried many solutions mentioned above, and none of them works. I realized maybe I just used wrong ssh agent... So I run echo $GIT_SSH to find out, it shows the path to Plink.exe. What I actually expected is OpenSSH.

So, I add following one-liner to ~/.zshrc file

Note 1: You can execute it in babun directly also
Note 2: You if you use bash then the config file is .bashrc

export GIT_SSH=$(which ssh)

And It works!

Paris Qian Sen
  • 1,020
  • 10
  • 21
2

use your https origin instead of ssh url

example:

git remote add origin  https://gitlab.com/user/folder.git
Zoe
  • 27,060
  • 21
  • 118
  • 148
stilo bit
  • 144
  • 1
  • 2
2

You can follow below steps -

  1. Check for existing keys- a. ls -al ~/.ssh

  2. Create key if does not exist- Paste the text below, substituting in your GitHub email address. a. ssh-keygen -t ed25519 -C "your_email@example.com" b. When you're prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location. c. At the prompt, type a secure passphrase.

  3. Adding your SSH key to the ssh-agent- Fire up the SSH agent and add the key

  4. eval ssh-agent -s

  5. ssh-add ~/.ssh/id_ed25519

  6. Adding key to Git account- Pull up the key and add to Github account

  7. cat ~/.ssh/id_ed25519.pub

  8. Navigate to Git account and add SSH key

M Murteza
  • 1,629
  • 15
  • 10
  • Note that "your GitHub email address" used to generate your ssh key should be the email address you registered on the GitHub website. I used a different email address and got the dreaded "Please make sure you have the correct access rights and the repository exists" error. Regenerating an ssh key with the email address I registered with GitHub, uploading that key to GitHub, and adding it to ssh-agent fixed the problem for me. – izkon Jun 25 '22 at 08:32
1

Try https instead of ssh. Choose the https option from project home page where you copy the clone url from.

Vedha Peri
  • 1,386
  • 2
  • 12
  • 11
1

For me i was having issue with company VPN, after disconnecting working fine.

Check connection with github using command ssh -vvvT git@github.com

ranjeet
  • 540
  • 7
  • 16
1

Similar issue:

I gave passphrase when Git-cloned using SSH URL for git.
So this error now shows up, each time I opened VS Code on Windows 10

Below fixed the issue:

1 . Run the below command in CMD

setx SSH_ASKPASS "C:\Program Files\Git\mingw64\libexec\git-core\git-gui--askpass"
setx DISPLAY needs-to-be-defined

2 . Exit CMD & VS Code

3 . Reopen VS Code

4 . VS Code now shows a popup dialog where we can enter passpharse

Above commands are for Windows OS, similar instructions will work for Linux/MAC.

Manohar Reddy Poreddy
  • 25,399
  • 9
  • 157
  • 140
1

Solution to linux terminal on Chromebook

I came to this issue when trying to clone a repo from github with an error prompt below:

kex_exchange_identification: Connection closed by remote host Connection closed by 28.0.3.132 port 22

I solved this by turning off my VPN.

Also, I was using linux on chromebook, whose SSH is controlled by chromebook‘s setting rather than the linux virtual machine. So I have to add the private key to SSH agent manually by command

eval "$(ssh-agent -s)" # start the ssh-agent
ssh-add ~/.ssh/id_rsa # add the secret key to the agent (not .pub file)

I would add this line in my ~/.bashrc file

Yabin CHENG
  • 91
  • 1
  • 4
0

Strangely I only received this error in 1 of my many repos.

My issue was after installing the new GitHub Desktop for Windows where the previous old GitHub for Win kept keys in ~/.ssh/github_rsa and ~/.ssh/github_rsa.pub where as the new GitHub for Win expects it in ~/.ssh/id_rsa so the solution was just renaming the existing private and public keys:

~/.ssh/github_rsa -> ~/.ssh/id_rsa
~/.ssh/github_rsa.pub -> ~/.ssh/id_rsa.pub

After which let me access the repo again without issue.

mythz
  • 141,670
  • 29
  • 246
  • 390
0

Very common mistake was done by me. I copied using clip command xclip -sel clip < ~/.ssh/id_rsa.pub, but during pasting into github key input box, I removed last newline using backspace, which actually changed the public key.

So, always copy & paste ssh public key as it is without removing last newline.

Amreesh Tyagi
  • 1,378
  • 15
  • 15
0

My case: I use Windows and I have more than 1 user account. I was receiving the same error and the fix was to start the git bash with administrator rights.

Luca Filip
  • 61
  • 5
0

If using ubuntu/linux try this:-

git config --global --unset credential.helper

Now Generate a Personal Access Token from Github Account by following below steps:-

>>GITHUB ACCOUNT 
>> Developer setting 
>> Personal Access Token 
>>Genrate new one with all acess & use it as your password !!

Window user watch below link:-

https://www.youtube.com/watch?v=fkKkojKYZ8U

Vel
  • 9,027
  • 6
  • 34
  • 66
Kartik Chandra
  • 390
  • 4
  • 9
  • A comment to this video says "better than stack overflow answers". Then please help make SO have the better answers again. It is good SO practice to always give the essential parts of the answer here. So, if you want to provide a solution for windows too, then give it here. You may still provide links, but these should be only for reference. – Adrian W Jan 28 '22 at 21:07
0

After trying out many of these fixes unsuccessfully, I was able to clone the repo using GitHub Desktop app.

iretex
  • 53
  • 9
0

After trying out multiple thing that didn't work. The following command worked for me: git remote set-r https://<Username>@github.com/<Org>/<Repo>.git

Then you can verify with: git remote -v

Note that in Mac you should have the Github credentials in the Keychain. See this SO question for that: Couldn't find github in keychain MacOS.

NewToCode
  • 174
  • 8
  • For generating a new Github SSH credential: https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent – NewToCode Mar 01 '23 at 04:14
0

My ssh config file permissions were okay, I needed to change the ownership of the files. This worked for me:

sudo chown -R $(whoami) .
Majid Alaeinia
  • 962
  • 2
  • 11
  • 27
0

I happened to run into the "Please make sure you have the correct access rights and the repository exists" error when trying to clone a remote server's etckeeper directory:

git clone normaluser@example.com:/etc

Not only is normaluser not git directory /etc/'s owner (it's user root's), but the /etc/.git/ directory can only be accessed by user root.

On the other hand, user normaluser is in the sudo group, so having the git pull-cooperating git processes on the remote side run under superuser privileges solves the problem.

git clone --upload-pack 'sudo git-upload-pack' normaluser@example:/etc         

The trick here is to provide git clone with the option --upload-pack 'sudo git-upload-pack'.

By default, when git clone has successfully established the ssh connection to the remote server, it spawns git-upload-pack, a git-protocol tool cooperating with client-local git-protocol tools. By telling git-clone to spawn sudo git-upload-pack instead, it receives all privileges to read from /etc/.

Now this works in my case as my remote server's sudo environment is set up to remember normaluser's sudo tty ticket:

# this is file /etc/sudoers or some other file inside directory /etc/sudoers.d/

Defaults:normaluser !tty_tickets

# ...

For the crafted git clone ... to succeed, a sudo tty ticket must first be obtained, e.g. by executing sudo whoami as user normaluser and providing the password manually.

In case this sudo tty ticket solution is not a choice, askpass can be leveraged:

git clone --upload-pack 'SUDO_ASKPASS=/path/to/some-askpass sudo -A git-upload-pack' normaluser@example.com:/etc  

Notice SUDO_ASKPASS=/path/to/some-askpass and sudo -A ...: these information will tell the remote sudo invocation to query the provided askpass executable to provide the password. This could be the X11 graphical ssh-askpass, which in turn would require a client-side X server and enabled X11 Forwarding on both client side or server side.

Alternatively a custom script-based askpass executable can be provided; the only requirement for such executable is to return the password on stdout.

Abdull
  • 26,371
  • 26
  • 130
  • 172
-1

For me it gave the same error of:

Please make sure you have the correct access rights and the repository exists.

A quick fix was to eliminate the ~/.ssh/config file

mv config config_old && touch config

eval "$(ssh-agent -s)"

git clone your_repo

As it turned out to be the config file that was corrupt and configured with two ids

Vel
  • 9,027
  • 6
  • 34
  • 66
-7

Go into your cmd and run this : git config --global http.sslverify false

Boris_Ndong
  • 247
  • 2
  • 4