Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I ssh from WSL in visual studio code?

I am using WSL on windows 10 to program, and recently discovered that VS code can be used to edit programs through SSH.

However, I normally SSH into my university's computers through WSL so i can access the files on those systems and use their GPUs.

Is there any way to SSH into WSL using vscode, and then ssh into my universities systems, and have access to their resources and filesystems from with within vscode?

like image 811
Dhruva Gowda Storz Avatar asked Feb 10 '20 12:02

Dhruva Gowda Storz


People also ask

Can I SSH in VS Code?

The Visual Studio Code Remote - SSH extension allows you to open a remote folder on any remote machine, virtual machine, or container with a running SSH server and take full advantage of VS Code's feature set. Once connected to a server, you can interact with files and folders anywhere on the remote filesystem.

Does Visual Studio work with WSL?

Visual Studio's WSL 2 toolset allows you to use Visual Studio to build and debug C++ code on WSL 2 distros without adding a SSH connection. You can already build and debug C++ code on WSL 1 distros using the native WSL 1 toolset introduced in Visual Studio 2019 version 16.1.


2 Answers

You can create ssh.bat file under windows with the content:

C:\Windows\system32\wsl.exe ssh %*

And than set VS Code setting "remote.SSH.path" to point to that bat file.
You’ll have the same ssh configuration and credentials in VS Code as you have in WSL.

like image 53
Hazzard17 Avatar answered Oct 11 '22 17:10

Hazzard17


If writing C:\Windows\system32\wsl.exe ssh %* in an ssh.bat file mostly works but gives you issues where your ~/.bashrc is not sourced, replace the command with

C:\Windows\system32\wsl.exe bash -ic 'ssh %*'

This tweak runs the ssh command in an interactive bash shell, which sources your ~/.bashrc. Using the above fixed an issue I had with the Ubuntu ssh-agent not forwarding keys on VSCode remote terminal.

like image 2
Julius Tao Avatar answered Oct 11 '22 16:10

Julius Tao