I am using Ubuntu 20.04 in the Windows subsystem for Linux on Windows 10. When I type the who
command I get no output:
renniej@ratitch:~$ whoami
renniej
renniej@ratitch:~$ who
renniej@ratitch:~$
I have tried various things like sudo who
and who -a
but still I get no output. who --version
gives:
who (GNU coreutils) 8.30
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Joseph Arceneaux, David MacKenzie, and Michael Stone.
Am I doing something silly here? Or is this a feature of WSL2?
Short answer
Nothing silly. There's a Github issue related to the root cause. While the WSL team originally tagged it "by design" and "feature", there was activity on it last year that indicates that it is "high value low cost."
Then again, more recently it's noted that it was created 5 years ago, and has no "thumbs up" from other users wanting it fixed. My guess is that this won't be changed until and unless WSL adopts a more Systemd-like approach to startup (see below for details).
Explanation
... or more than you probably ever wanted to know about
who
There are two reasons why
who
isn't showing any results:First, the obvious --
who
is designed to show (quoting from the man page), "who is logged in". When you start WSL, it doesn't actually send your user through the login password, which is the reason you don't get asked for a password.Second, WSL runs its own
/init
process as PID1 at startup, which does the "magic" of setting up things like:.exe
's to runA "normal" Linux system, on the other hand, starts up with Systemd or SysVInit (or a smattering of other init systems over the years). The init system is responsible for establishing the runlevel, among other things. And along with that (I'm just learning this myself from that Github issue), the
/var/run/utmp
construct, which is what tracks who is using the system.There are a few ways that you could "force" who to work:
The first is covered in that Github thread. First, hack a
/var/run/utmp
with something like:Then, force a "login" with
sudo login -f $USER
. You can then see your user logged in usingwho
. If you were to login again viassh
(you'd need to set it up first), then that login would also appear.Second, you could start Systemd in its own PID namespace:
Wait a few seconds for Systemd to start up, and it will initialize
/var/run/utmp
. Technically at this point you cansudo login -f $USER
and seewho
.Note that Systemd isn't fully usable without additional effort (beyond the scope of this answer), and that you must terminate the Ubuntu WSL instance after doing this in order to return to a stable state. Exit WSL and then
wsl --terminate <distro>
(where<distro>
is likelyubuntu
). Once you start back up, everything will be back to normal.