Score:0

Fail to connect to WSL2 via ssh

br flag

I have managed to connect to WSL2(win11) once on my MacBook. Then I restart windows machine to test ssh connection. But in this time, it fails, reporting kex_exchange_identification: read: Connection reset by peer

I've already added sshd: ALL in WSL and restart ssh service. But I still cannot connect to WSL. What can I do?

NotTheDr01ds avatar
vn flag
What is your purpose for ssh'ing from Mac to WSL2? My recommended setup steps for ssh are slightly different depending on your needs. Do you just need terminal access to your Windows machine through WSL2 from your Mac? Or something more like `scp`?
Cino avatar
br flag
Actually, I want to use WSL2 as a linux server.
Score:0
co flag

When rebooted WSL would pick a different IP, making your port forwarding settings invalid because packets will be forwarded to the old IP address which doesn't exist on your system anymore. You'd need to use some form of bridge more or static IP. Also scripting the setup might be helpful too.

Hanselman talked about this in more detail as well:

FORWARD PORTS INTO WSL2

Now, from an Administrator Windows prompt - that can be cmd.exe or powershell.exe, it doesn't matter, use the net shell "netsh" to add a portproxy rule. Again, change connectaddress to YOUR WSL2 ipaddress, which is an internal address to your machine.

netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=2222 connectaddress=<internal-IP> connectport=2222

As YOUR WSL2 ipaddress changes next boot, port forwarding stops working.

Hope it helps. Good luck.

Cino avatar
br flag
Ive already done that before. It does not work.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.