0

I just installed Ubuntu-24.04 from the Microsoft Store into WSL2 on my Windows 11 host. The first thing I wanted to install after logging in and upgrading the installation was openssh-server, but that fails.

This are the last lines of the installation command output:

Creating config file /etc/ssh/sshd_config with new version
Created symlink /etc/systemd/system/sockets.target.wants/ssh.socket → /usr/lib/systemd/system/ssh.socket.
Created symlink /etc/systemd/system/ssh.service.requires/ssh.socket → /usr/lib/systemd/system/ssh.socket.
Could not execute systemctl:  at /usr/bin/deb-systemd-invoke line 148.
dpkg: error processing package openssh-server (--configure):
 installed openssh-server package post-installation script subprocess returned error exit status 1
Processing triggers for man-db (2.12.0-4build2) ...
Processing triggers for libc-bin (2.39-0ubuntu8.1) ...
Errors were encountered while processing:
 openssh-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

In case it matters, here is my .wslconfig:

[wsl2]
kernel=C:\\WSL2\\bzImage
guiApplications=true
debugConsole=false
networkingMode=mirrored

[experimental]
hostAddressLoopback=true

The custom kernel is the 6.1.21.2-microsoft-standard-WSL2+ that Microsoft offers if one want to run a 6.x kernel with WSL2

Any insights what causes openssh-server install to fail?

3
  • systemd is enabled (by default on Ubuntu-24.04 in WSL2) Commented Apr 29 at 15:47
  • Yes, I can do "systemctl status" for the various units installed, of course not for ssh because it cannot be installed and isn't preinstalled. Believe me, systemd is up and running. Commented Apr 29 at 17:25
  • Ok, I identified the problem. Apparently, the install script tries to enable and start the service, listening on default port 22. Because I'm using mirrored networking and on my Windows Host ssh is already listening on Port 22, this results in a conflict. I've to create a conf file in /etc/ssh/sshd_config.d/ with a custom port number to avoid that conflict. Then everything works as expected. Commented Apr 29 at 17:40

1 Answer 1

1

Apparently, the install script of openssh-server tries to enable and start the service, listening on default port 22.

When you use mirrored networking, the ports between the Windows host and WSL are shared, and if also on Windows or another running WSL distribution ssh on port 22 is listening, the installer fails to start because port 22 is already in use.

I've to create a conf file in /etc/ssh/sshd_config.d/ with a custom port number to avoid that conflict. Then everything works as expected.

Example: Create file /etc/ssh/sshd_config.d/99-fixwslport.conf with this content

Port 50022

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .