SSH Server Setup in WSL2¶
Install¶
Configure /etc/ssh/sshd_config¶
Key directives to set/uncomment:
Port 22
ListenAddress 0.0.0.0
PermitRootLogin no
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication no
ChallengeResponseAuthentication no
UsePAM yes
Port conflict note: If Windows OpenSSH Server is installed and bound to port 22, use a different port (e.g., 2222). Check from PowerShell:
To disable Windows OpenSSH (recommended -- you want WSL2's sshd, not Windows'):
Generate Host Keys (if missing)¶
Start and Enable¶
With systemd enabled ([boot] systemd=true in /etc/wsl.conf):
Without systemd:
Verify¶
Auto-Start on WSL2 Boot¶
If using systemd, systemctl enable ssh handles this.
If not using systemd, add to /etc/wsl.conf:
Then wsl --shutdown from PowerShell and restart WSL2.