Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 915
carluri Avatar asked May 30 '19 17:05

carluri


2 Answers

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)

like image 137
Kuba Avatar answered Oct 11 '22 11:10

Kuba


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..:
      • Variable name: SSH_AUTH_SOCK
      • Variable value: /tmp/.ssh-pageant-username (e.g. /tmp/.ssh-pageant-bill) (Environment Variable assignment screenshot)
  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.

like image 38
JerryL Avatar answered Oct 11 '22 12:10

JerryL