I am trying to enable SSH in my Ubuntu running in WSL2 system:
sudo systemctl status ssh
I get this error:
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
What does it mean and how can I enable ssh?
A few things to note when trying to use SSH on WSL2:
systemd
init system and infrastructure, you'll need to rely on other methods. The WSL version of Ubuntu still provides the oldinit.d
style scripts for most services. So usingsudo service ssh start
(orrestart
, orstatus
, orstop
, etc.) is what you'll use.But that's just the beginning of it. WSL2 also runs in a VM with a virtual network interface that is NAT'd, so you won't be able to
ssh
into the WSL instance from any other machine on the network without additional effort. WSL does provide automatic localhost forwarding, though, so you canssh
in from Windows on the same machine, or from another WSL instance on the same machine.If you just need terminal access to WSL from a remote machine, then here's a far easier solution:
ssh -t windows_user@windows_host wsl
. That just connects to the Windows host, allocates a pseudo-terminal with-t
, and runs thewsl
command using that pseudo-terminal.If, on the other hand, you need real SSH access to the WSL instance, then the "usual answer" is fairly complicated still. See this Github comment and thread and my summary of your general options for port forwarding here.
That's "in general" though. For
ssh
we can make it easier by using an ssh server in both the Windows host and the WSL instance. See a "short version" of this in my answer here and (far) more details if you need them in this answer.The "far more details" answer also includes a solution to starting the ssh server remotely, since it won't automatically run at boot time under WSL.
For WSL you'll want to use the correct syntax:
This will give you what you're looking for: