Usually you can use the following command to specify the user to use when entering wsl:
wsl -u <Username>
If you want to modify the default user, you need to set it up. Here are two methods:
method one
First check the wsl version on the computer:
C:\Users\Administrator>wsl -l
适用于 Linux 的 Windows 子系统分发:
Ubuntu-22.04 (默认)
As you can see, my version here is Ubuntu2004, so the following settings are required. The code format is:
<DistributionName> config --default-user <Username>
For example, take my computer version as an example, set root as the user when entering, the code is as follows:
ubuntu2004.exe config --default-user root
Method Two
Or use wsl.conf
to configure, enter wsl, and edit the wsl.conf
configuration file:
sudo vim /etc/wsl.conf
Add the following:
[user]
default = root
Save the configuration and exit, and re-enter after closing wsl, you will find that the default user has been modified.
wsl --list --running
wsl --shutdown
wsl
It should be noted that wsl.conf
the configuration priority is higher than thatUbuntu2004.exe config --default-user
, so if both are configured, the configuration wsl.conf
in precedence.