How to Add, Remove, and List Sudo Users in Windows Subsystem for Linux (WSL) Distro in Windows 10
The Windows Subsystem for Linux (WSL) is a new Windows 10 feature that enables you to run native Linux command-line tools directly on Windows, alongside your traditional Windows desktop and modern store apps.
When you have Windows Subsystem for Linux (WSL) enabled, you can install WSL distro apps from the Microsoft Store, and export and import WSL distros.
The first time a newly installed WSL distro runs, a Console window will open, and you'll be asked to wait for a minute or two for the installation to complete.
Once installation is complete, you will be prompted to create a new user account (and its password).
Creating your Linux user is the first step in setting up a new Linux distribution on WSL. The first user account you create is automatically configured with a few special attributes:
- It is your default user -- it signs-in automatically on launch.
- It is Linux administrator (a member of the sudo group) by default.
Each Linux distribution running on the Windows Subsystem for Linux has its own Linux user accounts and passwords. You will have to configure a Linux user account any time you add a distribution, reinstall, or reset. Linux user accounts are not only independent per distribution, they are also independent from your Windows 10 user account.
When you add a user to a WSL distro, this new user will not be a member of the sudo (aka: administrator) group by default.
This tutorial will show you how to add, remove, and list users of the sudo group in a Windows Subsystem for Linux (WSL) distro in Windows 10.
CONTENTS:
- Option One: List All Sudo Users in a WSL Distro
- Option Two: Add User to Sudo Group in a WSL Distro while signed in as Root
- Option Three: Add User to Sudo Group in a WSL Distro while signed in as a Sudu User
- Option Four: Remove User from Sudo Group in a WSL Distro while signed in as Root
- Option Five: Remove User from Sudo Group in a WSL Distro while signed in as a Sudu User
OPTION ONE
List All Sudo Users in a WSL Distro
1. Open the WSL distro (ex: "Ubuntu") you want to list all
users that are currently a member of the sudo group in this WSL distro.
2. Copy and paste either command below into the WSL distro console, and press
Enter. (see screenshots below)
grep '^sudo:.*$' /etc/group | cut -d: -f4
OR
getent group sudo | cut -d: -f4
OR
grep -Po '^sudo.+:\K.*$' /etc/group
3. You will now see a list of all users that are currently a member of the sudo group in this WSL distro. Each user will be separated by a comma.
You can compare this list of sudo users to the list of all users to see which users are not currently a member of the sudo group.
OPTION TWO
Add User to Sudo Group in a WSL Distro while signed in as Root
1. Open the WSL distro (ex: "Ubuntu") you want to add a
user to the sudo group for this WSL distro.
2. Type the command below into the WSL distro console, and press
Enter. (see screenshot below)
gpasswd -a <username> sudo
Substitute <username> in the command above with the actual user (ex: "brink2") you want to add as a member of the sudo group for this WSL distro.
For example: gpasswd -a brink2 sudo
OPTION THREE
Add User to Sudo Group in a WSL Distro while signed in as a Sudu User
1. Open the WSL distro (ex: "Ubuntu") you want to add a
user to the sudo group for this WSL distro.
2. Type the command below into the WSL distro console, and press
Enter. (see screenshot below)
sudu gpasswd -a <username> sudo
Substitute <username> in the command above with the actual user (ex: "brink2") you want to add as a member of the sudo group for this WSL distro.
For example: sudu gpasswd -a brink2 sudo
3. When prompted, enter the password of the currently signed in sudo user (ex: "brink"), and press
Enter.
This will not be the password of the user (ex: "brink2") you want to add as a member of the sudo group.
OPTION FOUR
Remove User from Sudo Group in a WSL Distro while signed in as Root
1. Open the WSL distro (ex: "Ubuntu") you want to remove a
user from the sudo group for this WSL distro.
2. Type the command below into the WSL distro console, and press
Enter. (see screenshot below)
gpasswd -d <username> sudo
Substitute <username> in the command above with the actual user (ex: "brink2") you want to remove as a member of the sudo group for this WSL distro.
For example: gpasswd -d brink2 sudo
OPTION FIVE
Remove User from Sudo Group in a WSL Distro while signed in as a Sudu User
1. Open the WSL distro (ex: "Ubuntu") you want to remove a
user from the sudo group for this WSL distro.
2. Type the command below into the WSL distro console, and press
Enter. (see screenshot below)
sudu gpasswd -d <username> sudo
Substitute <username> in the command above with the actual user (ex: "brink2") you want to remove as a member of the sudo group for this WSL distro.
For example: sudu gpasswd -d brink2 sudo
3. When prompted, enter the password of the currently signed in sudo user (ex: "brink"), and press
Enter.
This will not be the password of the user (ex: "brink2") you want to remove as a member of the sudo group.
That's it,
Shawn