Unable to Connect WSL SSH Server (Remote Device): Connection Reset by Peer - Tech Support Guide
In this guide, you'll learn how to resolve the "Unable to Connect WSL SSH Server (Remote Device): Connection Reset by Peer" issue. Specifically, this guide is focused on installing an SSH server on Windows 11 with WSL 2 (Ubuntu 20.04 LTS). This guide assumes you have a fresh installation of WSL 2 with no other SSH tools installed.
1. Install OpenSSH Server on Ubuntu 20.04 LTS (WSL 2)
To start, ensure your WSL 2 instance (Ubuntu 20.04 LTS) is running. If it's the first time you launch the WSL 2 instance, it will take a while for the installation to complete. Now, update the package list:
sudo apt update
After updating the package list, you can proceed to install the OpenSSH server:
sudo apt install openssh-server
2. Configure OpenSSH Server
The SSH server will be configured automatically by the installation process. You can check its status using:
sudo systemctl status ssh
If it's active and running, great! you can proceed. If not, start and enable the service:
sudo systemctl start ssh
sudo systemctl enable ssh
3. Connect from Windows Terminal (WSL 2)
To check if the connection works from within the WSL 2 instance (Ubuntu 20.04 LTS), in the same terminal instance, type:
ssh localhost
You should accept the RSA key. After that, you should be able to connect. If not, check the logs using "sudo journalctl -f -u ssh".
4. Configure SSH Access from Windows 11
To allow incoming connections from Windows 11, you need to modify the /etc/ssh/sshd\_config file.
First of all, you need to allow connections from outside the localhost. Look for the following line (around line 30):
# What ports, IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress 0.0.0.0
#ListenAddress ::
Comment out the "#ListenAddress 0.0.0.0" and "#ListenAddress ::" lines using '#' in the beginning of the line. Make sure the "Port" line is not commented.
Then, add a "Match" block at the end of the file, before the last " "
# Allow users to connect using Windows passwords
Match User your-wsl-username
AuthenticationMethods publickey,password
Replace "your-wsl-username" with the username you want to allow the connection for (in case you have more than one). This configuration allows users to connect using an SSH key pair or a Windows password.
5. Restart OpenSSH Server
To make sure all changes apply, restart the SSH server:
sudo systemctl restart ssh
6. Allow Windows 11 Firewall Traffic
By default, Windows 11 firewall blocks all outside incoming connections. Go to "Settings" > "Privacy & Security" > "Windows Security" > "Firewall & network protection" > "Advanced settings".
On the new window, on the right side, find the "Inbound Rules" section. Click "New Rule". Select "Port" and "TCP". On the "Specific Local Ports" enter "22". Choose "Allow the connection" and click "Next". In the final step, choose "Domain, Private, Public" and finish the wizard.
7. Connect from Windows 11 Command Prompt / PowerShell
From the Windows Command Prompt or PowerShell, you can connect using:
ssh your-wsl-username@localhost -p 22
You will be asked for your Windows password. This setup should allow you to connect from Windows 11.