Written on 8/23/2020
Updated on 3/1/2022
I found Scott Hanselman’s blog article. it gave me good advice to make settings of WSL2 SSH server host. I brushed up and added some trick to the contents. After that, It becomes super easy way to access WSL2 SSH server from an external machine.
There are three main solutions.
$ sudo apt install ssh
...STUFF ABOVE THIS...
Port 2222
#AddressFamily any
ListenAddress 0.0.0.0
#ListenAddress ::
...Option Stuff
PasswordAuthentication yes
If you didn’t make these keys, or you want to recreate them, do so.
$ sudo ssh-keygen -t ecdsa -N '' -f /etc/ssh/ssh_host_ecdsa_key
$ sudo ssh-keygen -t ed25519 -N '' -f /etc/ssh/ssh_host_ed25519_key
$ sudo ssh-keygen -t rsa -N '' -f /etc/ssh/ssh_host_rsa_key
> netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=22 connectaddress=127.0.0.1 connectport=2222
You can run this from elevated command script file.
On Windows 10 firewall settiings, you have to open tcp port 22 and 2222.
$ sudo service ssh start
$ ssh your.Windows10.machine.address
https://www.hanselman.com/blog/CommentView.aspx
THE EASY WAY how to SSH into Bash and WSL2 on Windows 10 from an external machine
https://www.hanselman.com/blog/THEEASYWAYHowToSSHIntoBashAndWSL2OnWindows10FromAnExternalMachine.aspx