brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: wsl --distribution --user starts a specific distro as a specific user

CLI
~/tips/tip-windows-wsl-distribution-user-root

wsl --distribution <Distribution Name> --user <User Name>

Runs a chosen WSL distribution as a chosen Linux user, for example root, without changing the default.

Fixing a forgotten password or a broken file permission inside WSL usually needs root, and the default user is not root. You do not have to change the default user for that.

wsl --distribution <Distribution Name> --user <User Name>

For example, to open Debian as root:

wsl --distribution Debian --user root

The Microsoft documentation describes it as running a specific distribution with a specific user. If you have several distributions and are not sure about the exact name, wsl -l lists them.

To confirm who you are once inside, run whoami, which the documentation suggests for printing the current user name. A related option is wsl --user <Username> on its own, which runs WSL as that user in the default distribution.

The user has to exist inside the distribution. If it does not, you get an error. Note also that wsl --user works per call. For a permanent change of the default login user, the documentation points to <DistributionName> config --default-user, which does not work for imported distributions. For those you set the user in /etc/wsl.conf.

None of this was run on a live Windows machine here. It follows the Microsoft documentation.

Further reading: Basic commands for WSL

More CLI tips wsl --shutdown Compress-Archive -Path C:\Reference -DestinationPath C:\Archives\Draft.zip wsl --terminate <Distribution Name> rg -o -r '$2' '"(GET|POST) (\S+)' access.log redis-cli --json HGETALL user All CLI tips (60) All topics

Link