Neve
Neve

Reputation: 417

I can push and pull changes to GitHub using GitBash but getting Permission Denied (publickey) error in Visual Studio

I use GitLab at work with Visual Studio and it's all fine I use HTTPS for those

I also have some projects of my own on Github that are on my personal PC I want to work on one of them on my work PC

So I tried to set it up by cloning it from GIT and using SSH I went through the setting up the key part, checking it works I can now push and pull changes using GitBash But whenever I try to use Visual Studio to do the same thing I get this error

Git failed with a fatal error. failed to acquire credentials. [email protected]: Permission denied (publickey). Could not read from remote repository.Please make sure you have the correct access rights and the repository exists.

I am obviously missing something here, perhaps related to the fact I have VS working with my work repos... I'm really not sure. I would appreciate any suggestions.

Upvotes: 1

Views: 87

Answers (1)

VonC
VonC

Reputation: 1326616

You could try and launch VSCode again after setting GIT_SSH_COMMAND to "ssh -v"

# Linux
export GIT_SSH_COMMAND='ssh -v'
# Windows
set GIT_SSH_COMMAND="ssh -v"

code path/to/specific/folder

You would see where git is trying to access and use SSH keys.

If VSCode is launched with a different user than the regular current user, it would not access the private key whose public part has been registered to your GitHub account.

If the private key is passphrase protected, don't forget to add it to the ssh-agent first (ssh-add ~/.ssh/id_rsa).

Upvotes: 1

Related Questions