Skip to content

Instantly share code, notes, and snippets.

@bubba-h57
Last active October 23, 2023 12:46
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save bubba-h57/3b212d8a8d56e1c35218515dd220371c to your computer and use it in GitHub Desktop.
Save bubba-h57/3b212d8a8d56e1c35218515dd220371c to your computer and use it in GitHub Desktop.
Configuring Jetbrains Gateway and WSL

Step 1: SSH Daemon

In your WSL instance, re-install OpenSSH server as follows.

sudo apt remove --purge openssh-server
sudo apt install openssh-server

Edit /etc/ssh/sshd_config (e.g. sudo vi /etc/ssh/sshd_config) and add the following lines to the bottom of the file. Ensure you replace WSL_ACCOUNT_NAME with your WSL2 account name.

PasswordAuthentication yes
AllowUsers WSL_ACCOUNT_NAME 

(Optional) For security, allow only specific IP addresses to login. E.g. to allow 192.30.118.x and 194.57.240.32 only, do as follows. edit as follows.

Edit /etc/hosts.deny (e.g. sudo vi /etc/hosts.deny). and add the floowing line:

sshd: 192.30.118.0/24 194.57.240.32

Restart the SSH server.

sudo service ssh --full-restart

Allow SSH server to start without password. Run sudo visudo and find the %sudo ALL=(ALL:ALL) ALL. Immediately below that line, add this line.

%sudo ALL=NOPASSWD: /etc/init.d/ssh

Step 2: Auto Start SSH Daemon

In /etc/wsl.conf:

[boot]
command = service ssh start
See https://learn.microsoft.com/en-us/windows/wsl/wsl-config for the documentation of the WSL config files

Or check out this StackExchange answer.

Step 3: Resolve WSL Hostname

Microsoft hasn't built this in for you. Fortunately, Shane did. Install and setup the go-wsl2-host service. That will then handle the DNS resolution for your WSL instance.

Step 4. Jetbrains Gateway

Download and install Jetbrains Gateway. Once you have it running, configure an SSH connection to your WSL instance, and map a project directory. Choose the Jetbrains IDE you want to use and go to it. The gateway will download and install an agent (headless client) that will run locally within the WSL instance.

@markusheiden
Copy link

markusheiden commented Sep 24, 2022

There is an easier way to autostart the SSH server in WSL 2:

In /etc/wsl.conf:

[boot]
command = service ssh start

See https://learn.microsoft.com/en-us/windows/wsl/wsl-config for the documentation of the WSL config files

@bubba-h57
Copy link
Author

Thanks @markusheiden

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment