Run wsl --manage <Distro> --set-default-user <Username> from PowerShell. No config file editing required.
WSL logs you in as the account you created when the distribution first started. That is fine until you want it to open as root for setup work, or you created the account with a typo and have been living with it ever since.
Change It
# see the distro names exactly as WSL knows them wsl -l -v # set the default user for one distribution wsl --manage Ubuntu --set-default-user peter # log in as root instead wsl --manage Ubuntu --set-default-user root
The change applies the next time you start that distribution. If a session is already open, close it, or run wsl --terminate Ubuntu first.
The Older Methods You Will Find Online
Most guides still describe one of two older approaches, and both still work:
# 1. the distro launcher ubuntu config --default-user peter # 2. /etc/wsl.conf inside the distribution [user] default=peter
The launcher method needs the executable name to match your distro, which is fiddly once you have several. The wsl.conf method means editing a file inside a distribution you might not be able to log into, which is awkward precisely when you need it most. The --manage command avoids both problems.
root with the same command, then create the account properly with adduser.Related
If SQL Server is part of your day job, my current work lives over at sqldba.blog: production DBA scripts, an error library and the SSMS guide.
Leave a Reply