Solved After entering systemd namespace, ssh service can't bind to ssh port because address already in use

Solved issue

zzzhhh

New Member
Joined
Jan 5, 2024
Messages
6
Reaction score
1
Credits
87
I installed Ubuntu 22.04.3 LTS in WSL2 according to instructions here.

Then I installed SSH server according to instructions here.

Then I installed ubuntu-wsl2-systemd-script to enable systemd support in WSL2. During reboot of Ubuntu in WSL2, line 45-47 of enter-systemd-namespace script enters systemd namespace:
exec /usr/bin/nsenter -t "$SYSTEMD_PID" -a \
/bin/login -p -f "$SUDO_USER" \
$([ -f "$USER_HOME/.systemd-env" ] && /bin/cat "$USER_HOME/.systemd-env" | xargs printf ' %q')
But this makes the SSH service stop working. If I run systemctl status ssh.service, I got the following error messages:
Jan 04 09:01:48 DESKTOP-J2VCDBO systemd[1]: Starting OpenBSD Secure Shell server...
Jan 04 09:01:48 DESKTOP-J2VCDBO sshd[246]: error: Bind to port 2022 on 0.0.0.0 failed: Address already in use.
Jan 04 09:01:48 DESKTOP-J2VCDBO sshd[246]: error: Bind to port 2022 on :: failed: Address already in use.
Jan 04 09:01:48 DESKTOP-J2VCDBO sshd[246]: fatal: Cannot bind any address.
Jan 04 09:01:48 DESKTOP-J2VCDBO systemd[1]: ssh.service: Main process exited, code=exited, status=255/EXCEPTION
Jan 04 09:01:48 DESKTOP-J2VCDBO systemd[1]: ssh.service: Failed with result 'exit-code'.
Jan 04 09:01:48 DESKTOP-J2VCDBO systemd[1]: Failed to start OpenBSD Secure Shell server.

I cannot find out what processes are using port 2022 because the results returned from sudo netstat -tulnp | grep 2022 contain no process information:
tcp 0 0 0.0.0.0:2022 0.0.0.0:* LISTEN -
tcp6 0 0 :::2022 :::* LISTEN -

So, how can I keep (most of) ubuntu-wsl2-systemd-script while have SSH service working?
 


Problem solved.

WSL released a new version 2.0.14 this morning, after I submitted this ticket (what a coincidence). In this version of WSL, SSH server and systemd don't fight each other any more (though systemctl reports the SSH service is inactive (dead)).
 
@zzzhhh , you can go to your first Post and edit to include a Solved sign as below

nYSKHvh.png


Cheers

Wizard
 

Staff online


Top