Windows 11 Install WSL2 and SSH Remote Connection

Manual installation (WSL2)
First search [Enable or turn the WinSOWS function]

Then check [Windows Subsystem for Linux] and [Virtual Platform]

Install the selected Linux Distribution Edition Open the Microsoft Store, search for WSL2 and select your preference Linux distribution

WSL is different from WSL2, I remember that SSH can be connected when it is not upgraded to WSL2, and WSL2 seems to be.
ReferenceSSH connection WSL2 Ubuntu 18.04

First, reinstall OpenSSH-Server

  1. Enter the Ubuntu subsystem to remove OpenSSH-Server

sudo apt purge openssh-server
2. Reinstall OpenSSH-Server

sudo apt install openssh-server

Second, restart WSL

Open PowerShell.exe and enter the following command

sudo net stop LxssManager
and then start

sudo net start LxssManager

Third, start SSH

  1. Enter WSL and type the following command
    sudo service ssh start
  2. View the SSH service status, whether to start success
    service ssh status
    If you displaysshd service is runningThe word is successful!

Fourth, set the SSH service to boot

sudo systemctl enable ssh

V. Precautions

During the search information, many articles mentionedThe problem of port conflicts may result in connecting the SSHI didn’t encounter this problem, or the default 22 port. If you still have problems according to the above operation, you can try to change the port.The configuration file is in the / etc / ssh / sshd_config file. Find the sentence of “Port 22”, change 22 to 2222, restart SSHTry to see if you can do it.