2020年6月23日 星期二

[WSL2] ssh into Ubuntu


 Windows 10   WSL2   Ubuntu  


Problem


Cannot ssh into WSL2 Ubuntu and got the error:

$ ssh root@localhost -p 22
ssh_exchange_identification: Connection closed by remote host



Solution


1. Reinstall SSH Server

$ sudo apt-get purge openssh-server
$ sudo apt-get install openssh-server


2. Update/Enable the values in /etc/ssh/sshd_config


First change the owner of sshd_config, (and change it back to root after everything is done)

$ sudo chown <current_user> /etc/ssh/sshd_config




Key
Value
Note
PermitRootLogin
yes
The value can be yes, prohibit-password, forced-commands-only, or no.
PasswordAuthentication
yes



You can also change the following values for ssh into it from remote machine,

Key
Sample Value
Note
ListneAddress
0.0.0.0

Port
2222
Notice that Windows 10/Server 201 had used port 22 for its own SSH server



3. Restart SSH-Server Service

$ sudo service ssh --full-restart






Reference









沒有留言:

張貼留言