microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.05k stars 797 forks source link

ssh client cannot disconnect from ssh server started by wsl.conf boot command #8324

Open andyli opened 2 years ago

andyli commented 2 years ago

Version

Microsoft Windows [Version 10.0.22598.200]

WSL Version

Kernel Version

Linux version 5.10.102.1-microsoft-standard-WSL2 (oe-user@oe-host) (x86_64-msft-linux-gcc (GCC) 9.3.0, GNU ld (GNU Binutils) 2.34.0.20200220) #1 SMP Wed Mar 2 00:30:59 UTC 2022

Distro Version

Ubuntu 20.04

Other Software

OpenSSH_8.2p1 Ubuntu-4ubuntu0.4, OpenSSL 1.1.1f 31 Mar 2020

Repro Steps

I use wsl.conf's [boot] command to start ssh server:

andy@DESKTOP-BB6FOD7:/mnt/c/Users/andy$ cat /etc/wsl.conf
[boot]
command="service ssh start"

I could connect to the ssh server running in wsl successfully, but when I issue exit, the ssh client terminal become blank and did not return to prompt. If I close the terminal window and re-connect with ssh, there is a zombie process in wsl.

Expected Behavior

ssh client should exit and return to prompt immediately without any zombie processes.

Actual Behavior

ssh client terminal become blank and did not return to prompt. If I close the terminal window and re-connect with ssh, there is a zombie process in wsl.

A workaround is to add sudo in the wsl.conf boot command

andy@DESKTOP-BB6FOD7:/mnt/c/Users/andy$ cat /etc/wsl.conf
[boot]
command="sudo service ssh start"

Somehow with sudo, ssh clients were able to exit and returned to prompt immediately.

Diagnostic Logs

No response

elsaco commented 2 years ago

@andyli quick test: comment out ssh command in wsl.conf and start the server in debug mode with sudo /usr/sbin/sshd -ddd then connect from another terminal. This will show what's going on when the client exits. Please post ssh debug output.

andyli commented 2 years ago

I just did sudo /usr/sbin/sshd -ddd, ssh client connected and exited, somehow the sshd process also exited when the client exit. The log is at https://gist.github.com/andyli/60b5832cf37862c3d133e96cc56008aa

Note that I had to do a sudo mkdir -p /var/run/sshd before starting sshd, or else there is an error Missing privilege separation directory: /run/sshd.

Toug19 commented 1 year ago

I'm having same issue where ubuntu prompt doesn't come when exiting from ssh console connection. Terminal stays stuck and I have to close the window and open a new one. Windows 10 21H2 WSL 2 Ubuntu 20.04

ekamiti commented 1 year ago

I have the same issue. I can ssh in but the process gets zombied on exit and the prompt never returns.

Windows 11 22H2 WSL 2 Ubuntu 20.04