WSL user and root management¶
User and root management in the Windows Subsystem for Linux (WSL) involves configuring the default user, setting passwords for the root and standard accounts, and managing the lifecycle of WSL instances. These operations are typically performed from the Windows command line using the wsl command or by directly modifying configuration files within the Linux environment.
Default user configuration¶
WSL instances can be configured to launch with a specific user automatically by editing the /etc/wsl.conf file inside the Linux distribution. This requires appending the [user] section with a default variable set to the desired username^[400-devops-02-os-and-linux-basics-windows-wsl.md].
[user]
default=$myUsername
After modifying this file, the WSL instance usually needs to be restarted for the changes to take effect^[400-devops-02-os-and-linux-basics-windows-wsl.md].
Root password management¶
Accessing the root account requires switching to the root user via the Windows command line wrapper. This is achieved by targeting the specific distribution with the -d flag and the user with the -u flag^[400-devops-02-os-and-linux-basics-windows-wsl.md].
Once in the root shell, the password can be updated using the passwd command^[400-devops-02-os-and-linux-basics-windows-wsl.md].
wsl -d <DistroName> -u root
passwd root
User password management¶
Standard user accounts are managed within the Linux environment using the passwd command followed by the username^[400-devops-02-os-and-linux-basics-windows-wsl.md].
It is also common practice to ensure system utilities are up to date when managing users, which may involve package manager commands such as yum or apt^[400-devops-02-os-and-linux-basics-windows-wsl.md].
passwd $myUsername
Instance management¶
To apply configuration changes or perform maintenance on the user environment, it is often necessary to terminate the running WSL instance. This can be done using the --terminate command followed by the distribution name^[400-devops-02-os-and-linux-basics-windows-wsl.md].
Related¶
- [[WSL]]
- [[User management]]
- [[Linux permissions]]
Sources¶
^[400-devops-02-os-and-linux-basics-windows-wsl.md]