8

I have vs code configured to use the git bash as a terminal in windows 7.
"terminal.integrated.shell.windows": "C:\Program Files\Git\bin\bash.exe"

I have enabled SSH key based authentication to remotely access a host. All this works fine from within the terminal in VS Code.

However, when using the vscode-remote SSH extension to connect to host I get an error because it tries to connect using "The terminal process command 'cmd.exe'" instead of git bash.

I've checked my terminal settings configuration in vs code and it points to git bash.exe

I've used the terminal extension in vs code and it opens a git bash and successfully connects to the host

Is there a setting that I'm missing to force Remote-SSH to use the git bash for the connection?

carluri
  • 93
  • 2
  • 6

3 Answers3

10

JerryL's answer lead me to realize, that I can simply set GIT's ssh path c:\Program Files\Git\usr\bin\ssh.exe in the remote.SSH.path setting of VS Code Preferences:

enter image description here

Then it just worked like a charm.

Just for clarity my VS Code version is: 1.40.0-insider (system setup)

Kuba
  • 510
  • 3
  • 13
2

I ran into a similar issue trying to get MS VS Code Studio Remote-SSH working with Putty's Pageant. I had Git for Windows installed and in a Git Bash shell, I could ssh and pick up the Pageant keys and no password was needed.

But VS Code Remote-SSH, while using the Git ssh in C:\Program Files\Git\usr\bin\ssh.exe was using Windows 7 cmd.exe shell which didn't talk to Pageant.

What worked for me on Windows 7, VS Code 1.36.1 with (Remote Development 0.15.0, Remote-SSH 0.44.0) and Git for Windows 2.22:

  1. Start Pageant (C:\Program Files\PuTTY\pageant.exe) and Add key.
  2. Start the ssh agent shim (C:\Program Files\Git\cmd\start-ssh-pageant.cmd). This takes care of the communication between Git ssh, which looks for ssh-agent, and Pageant.
  3. Create the SSH_AUTH_SOCK environment variable
    1. Control Panel / System / Advanced Settings / Environment Variables..
    2. User variables for username / New..:
  4. Test ssh:
    1. Open a command prompt: Enter set to view the list of Environment Variables. Is the SSH_AUTH_SOCK variable set correctly to something like /tmp/.ssh-pageant-bill?
    2. Try ssh to your host using Git's ssh.exe: c:\Program Files\Git\usr\bin\ssh.exe user@host If this works, then VS Code Remote-SSH should work.

Finally, I added Pageant and start-ssh-pageant.cmd to my Windows 7 Startup so this persists across reboots.

Hope that helps.

Jerry.

JerryL
  • 21
  • 4
1

I had a similar problem trying to get VS Code Remote use Putty Pageant.

1. Create .bat file somewhere with the following content:

echo OpenSSH
"C:\YOUR_PATH_HERE\PLINK.EXE" -ssh %*

2. Open VS Code settings, type remote ssh path in search and find Remote.SSH: Path settings
3. Past here path to your .bat file
4. Now VS Code Remote will use Pageant correctly.

user0103
  • 1,246
  • 3
  • 18
  • 36
  • 1
    Unfortunately, this doesn't work for custom SSH ports. `ssh.exe` expects `-p XXXX` and `plink.exe` expects capital `-P xxxx`. A second problem is that you need to manually run the generated command outside of VSC the first time to accept the saving of the fingerprint key. You can probably get around that one by changing the bat file line to `echo y | "C:\YOUR_PATH_HERE\PLINK.EXE" -ssh %*` – fred Jun 14 '20 at 19:05
  • @fred A slightly modified batch script from this SO answer will change -p to -P: https://stackoverflow.com/a/14723487/409149 (remember to put `echo OpenSSH`). I used it with my VS Code and it works. Although I still had to manually accept the fingerprint. – pepkin88 Feb 14 '21 at 17:00