简体   繁体   中英

"You've successfully authenticated, but GitHub does not provide shell access" after running through all the ssh setup steps

I'm so confused. I'm trying to get the git clone command working, but it keeps saying:

git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

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

I feel I have done all the correct steps, though.

1- I've installed git. When I do git --version it says git version 2.17.1 .

2- I've also done ssh-keygen -t ed25519 -C "my_email@example.com" and see the id_ed25519.pub file in my .ssh folder.

3- I've done eval "$(ssh-agent -s)" and ssh-add ~/.ssh/id_ed25519 and have added copied the contents of id_ed25519.pub into my Github as an SSH key.

Then when I do

ssh -T git@github.com

I get:

The authenticity of host 'github.com (140.82.114.4)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,140.82.114.4' (RSA) to the list of known hosts.
Hi nightfarrow! You've successfully authenticated, but GitHub does not provide shell access.
Please make sure you have the correct access rights

and if I try to do

sudo git clone --recursive git@github.com:shubham-goel/ucmr.git

I get that fatal: Could not read from remote repository. error.

What might be the issue at this point? How can this problem be diagnosed? Thank you.

You're seeing problems because you're using sudo .

When you use an SSH key, that comes from your user's home directory, and when you use an SSH agent, that comes from the environment. When you use sudo , you change the current user, so the keys come from root's home directory, and sudo , by default, clears the environment for security reasons. Therefore, there is no possible way to get access to your keys, and your operation fails.

Unless you have a compelling reason, you should avoid sudo here because it's not needed. If you're sure you need it and you're certain that there's nothing in your PATH or the rest of the environment that might be a security risk, you can try to use sudo -E , which will avoid clearing the environment and therefore let your SSH agent work with your clone.

sudo -E copies the environment variables - If it is configured as an option in the sudoers file.

I got this issue too and solved it as below..

The only code that solved it for me was to set the remote url on my local machine by copying the ssh url type of my repository; on github presently they are three; Github CLI, Https and SSH and I was initially using Https url before they stopped using password authentication; https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ . So after getting to this point I encountered this error and below code fixed it.

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

replace git@github.com:username/your-repository.git with your ssh url from git hub.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM