Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Configuring External SSH Access to WSL on Windows

Tech 1

Installing OpenSSH in WSL

Begin by reinstalling OpenSSH server in your WSL instance:

sudo apt-get remove openssh-server
sudo apt-get install openssh-server

Modify the SSH server configuration:

sudo vi /etc/ssh/sshd_config

Update these crtiical parameters:

Port 22
PermitRootLogin Yes
PasswordAuthentication Yes

Automated Service Startup

Create a startup script to automatically launch the SSH service when WSL starts.

Port Forwarding Configuration

wslname = "Ubuntu-20.04"
wslport = "2222"
winport = "2222"

Set objShell = CreateObject("WScript.Shell")
objShell.Run "cmd /c wsl -d Ubuntu-20.04 -u root /etc/init.wsl start", 0, True
objShell.Run "cmd /c ""wsl -d " & wslname & " -u root hostname -I"">C:\Windows\Temp\wslip.tmp", 0, True

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("C:\Windows\Temp\wslip.tmp", 1)
wslip = f.ReadAll()
f.Close()

objShell.Run "cmd /c ""netsh interface portproxy add v4tov4 listenport=" & winport & " listenaddress=0.0.0.0 connectport=" & wslport & " connectaddress=" & wslip, 0, True
fso.DeleteFile("C:\Windows\Temp\wslip.tmp")

Automatic Startup Methods

Method 1: Startup Folder Place your script in the user's startup folder (accessible via shell:startup).

Method 2: Scheduled Task Create a task with these properties:

  1. Run with highest privileges
  2. Set triggger for system startup
  3. Action to execute your VBS script
  4. Configure additional conditions as needed

Verification

Check succesfull port forwarding with:

wsl --list --running
netsh interface portproxy show all

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

SBUS Signal Analysis and Communication Implementation Using STM32 with Fus Remote Controller

Overview In a recent project, I utilized the SBUS protocol with the Fus remote controller to control a vehicle's basic operations, including movement, lights, and mode switching. This article is aimed...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.