carluri
carluri

Reputation: 103

How to get vscode-remote-ssh extension connects via git bash in windows?

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?

Upvotes: 9

Views: 12220

Answers (3)

user0103
user0103

Reputation: 1272

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.

Upvotes: 1

Kuba
Kuba

Reputation: 540

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)

Upvotes: 12

JerryL
JerryL

Reputation: 21

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.

Upvotes: 2

Related Questions