nightfarrow
nightfarrow

Reputation: 113

"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:

[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.

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 "[email protected]" 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 [email protected]

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 [email protected]: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.

Upvotes: 9

Views: 28874

Answers (3)

Dlaw
Dlaw

Reputation: 173

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 [email protected]:username/your-repository.git

replace [email protected]:username/your-repository.git with your ssh url from git hub.

Upvotes: 9

Stevie P
Stevie P

Reputation: 11

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

Upvotes: 0

bk2204
bk2204

Reputation: 77034

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.

Upvotes: 14

Related Questions