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
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.
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.
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.
Thanks!