The problem is, I can't get the initial prompt back to enter a username & password, which, from what I understand, is how a new user is properly created for the virtual WSL Ubuntu instance.
Right. The initial user creation is done when the distribution executable (the .exe
that is installed from the Microsoft Store) is run for the first time. In the case of Ubuntu, that's typically ubuntu.exe
, although it can differ depending on if you installed a "named version" in the Store (e.g. Ubuntu 20.04 specifically). That said, it is entirely possible to create a default user manually (see below).
Let's start with wsl -l -v
to see what the distribution name is. It will most likely be just "Ubuntu", but modify the below commands if it is different.
The "easy" button
It's possible to get back to the initial "configuration" state, with the big assumption and caveat that doing so will erase all data/configuration in the instance (the virtual filesystem, etc.). That command is wsl --unregister Ubuntu
.
After doing that, you should simply be able to re-run "Ubuntu" from the Start Menu, and the distribution will be recreated. It will then ask you for the default username/password.
Running as root, without the need for sudo
A neat trick that you will probably find useful is that WSL can be started with any available user, including root
, without the need for a password:
wsl ~ -u root
wsl ~ -u fred
While you might initially be alarmed by the ability to run root without a password, keep in mind that, even as root, your permissions in WSL can never exceed your Windows user permissions. That said, please never do this.
Sidebar: Your questions
First, to answer some of your questions:
Should the account be a system account, and should it use an arbitrary name assigned by Ubuntu?
Not sure what you mean here exactly, but the answer, I believe, is "no". The default user can be named whatever you like. I recommend just using your normally preferred user name for convenience.
Should the account have a home directory?
Yes, and that home directory should be in /home
, not on a Windows mounted drive (e.g. /mnt/c
).
Is the sudo-group admin:sudo the only group that the top-security-level admin account (aka Sudo-account) needs to be added to, should I make another group with the same name as the Admin account I am creating?
The default Ubuntu method (both "pure Linux" and "WSL") is to create a group with the same name as the username. While perhaps not required, I would consider that a "best-practice".
Creating a new "default" WSL user without reinstalling
As far as I can tell, the following will create the default user with the same settings that the stock installer/configuration does. From within Ubuntu:
useradd --create-home --user-group --groups adm,dialout,cdrom,floppy,sudo,audio,dip,video,plugdev,netdev --password "encryptedPassword" username
Of course, modifying username
to be whatever you want. Since you are already running as root, no need for sudo
or any trickery there, of course, but other readers without the OP's use-case may need sudo
or wsl -u root
(as documented in this answer).
Of course, most of these groups probably aren't strictly necessary under WSL, but who knows - Some apps may expect some of them, and better safe than sorry. Again, this is the "stock" group list that is provided for the user when created by the Ubuntu/WSL configurator.
See here for how to create the encrypted password. Specifically (although personally untested for this exact command-line):
useradd --create-home --user-group --groups adm,dialout,cdrom,floppy,sudo,audio,dip,video,plugdev,netdev --password $(read -sp Password: pw ; echo $pw | openssl passwd -1 -stdin) username
Setting the default WSL user
"Normally", the WSL distro installer (e.g. ubuntu.exe
) modifies the Windows Registry with the default user name for the distro. I recommend a newer method, though. As root, create a file /etc/wsl.conf
with the following contents:
[user]
default=username
Again, of course, substituting your username
.
For alternative techniques, see this question and its various answers.
Recommended next steps
I personally recommend backing up this "ready-to-run" copy of your distribution at this stage. Again, from PowerShell:
wsl --export Ubuntu "2021-08-26 Default Ubuntu 20.04.tar"
If you need to spin up a throwaway WSL instance for testing something out without modifying your "daily driver", you can easily wsl --import
this distribution (calling it something other than just "Ubuntu"), then throw it away with wsl --unregister
.