Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code SSH push and pull is working in command line but not with the push and pull buttons

I am trying to set up a programming environment for python with Visual Studio Code, git, and GitHub remote repo on Windows 10. I set up an SSH key and git repo on my local device. I then set up a repo on GitHub and added my SSH key to my account. I added the remote source on my local machine to point to the repo on gitHub.

I spent a while with connection issues and finally discovered I needed to enable the SSH service on my computer.

Once I got everything connected, I had an issue with merging the fetched repo that I overcame by adding the --allow-unrelated-histories flag. Once I added that flag the first time, I could push and pull freely with the remote repo using the command line on my local machine without using the flag. Any push or pull request would require me to enter my password.

I can use the Visual Studio Code to do everything with git on my local machine. Whenever I try to pull, I have the option to pull from the repo and select which branch I want to pull. However, when I actually try to pull using the pull to option, I get an error saying

Git: [email protected]: Permission denied (publickey).

My console output in VSC says

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

git show :Main.py

git status -z -u

git symbolic-ref --short HEAD

git rev-parse master

git rev-parse --symbolic-full-name master@{u}

git rev-list --left-right master...refs/remotes/origin/master

git for-each-ref --format %(refname) %(objectname) --sort -committerdate

git remote --verbose

Is this because, when using VSC's pull, it does not enter my SSH password automatically?

like image 266
Tucker Avatar asked Oct 27 '25 13:10

Tucker


1 Answers

Check VSCode Enabling alternate SSH authentication methods:

If you are connecting to an SSH remote host and are either:

  • connecting with two-factor authentication,
  • using password authentication,
  • using an SSH key with a passphrase when the SSH Agent is not running or accessible,

...VS Code should automatically prompt you to enter needed information.
If you do not see the prompt, enable the remote.SSH.showLoginTerminal setting in VS Code. This setting displays the terminal whenever VS Code runs an SSH command.
You can then enter your auth code, password, or passphrase when the terminal appears.

But if your ssh-agent is running (as described here), make sure to launch VSCode from the CMD session where you have checked that said agent is working.


I am not "connecting to an SSH remote host". I've already done it. What I'm trying to do - is use VSCode's UI to "sync with a remote" git repo.

In my case, here is the setup I have: I'm using a Windows VSCode app which is connected to a remote linux machine. In the remote linux machine - I have created the private/public ssh key pair, and added a public key to my git provider (GitLab).

When pushing/pulling from the command line - I enter my ssh passphrase and it works. When using the VSCode's UI - I get the error described above.

Since command-line operations work as expected, this indicates that your SSH keys and their passphrase are correctly set up, but VSCode may not be leveraging the SSH agent or is unable to prompt for the passphrase when needed.

Make sure that:

  • the SSH agent is running on your remote Linux machine and that VSCode is aware of it. If you are using ssh-agent, you can add your SSH key to the agent using ssh-add ~/.ssh/your-ssh-key. Verify that the agent is running and that VSCode can access it.
    Try launching VSCode from a terminal session where you have confirmed the SSH agent is running and accessible. That approach can make sure VSCode inherits the necessary environment variables to interact with the SSH agent.
  • your VSCode is configured to use the SSH agent. You might need to set the SSH_AUTH_SOCK environment variable correctly in VSCode's terminal or in the environment from which VSCode is launched. That variable helps VSCode locate the SSH agent socket (as illustrated in this issue).
like image 173
VonC Avatar answered Oct 30 '25 05:10

VonC