Add or Remove Sudo Users in WSL Linux in Windows 10

Continuing with my WSL coverage, I would like to share how to add or remove a user to the sudo group in a WSL Linux distro in order to allow or deny it from running commands and apps as root. This is applicable to newly added user accounts, as they have no sudo privileges out of the box. Also, we will see how to find which user accounts are already members of the sudo group.

The ability to run Linux natively in Windows 10 is provided by the WSL feature. WSL stands for Windows Subsystem for Linux, which initially, was limited to Ubuntu only. Modern versions of WSL allow installing and running multiple Linux distros from Microsoft Store.

Linux Distros Microsoft Store Windows 10

Tip: Here's how to tweak your PC to ensure top performance for a specific type of task, be it gaming, document work or something else.

After enabling WSL, you can install various Linux versions from the Store. You can use the following links:

  1. Ubuntu
  2. openSUSE Leap
  3. SUSE Linux Enterprise Server
  4. Kali Linux for WSL
  5. Debian GNU/Linux

and more.

When you start a WSL distro for the first time, it opens a console window with a progress bar. After a moment of waiting, you will be prompted to type a new user account name, and its password. This account will be your default WSL user account that will be used to sign-in automatically every time you run the current distro. Also, it will be included in the 'sudo' group in order to allow it to run commands elevated (as root).

User Accounts in WSL Linux

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 distributionreinstall, or reset. Linux user accounts are not only independent per distribution, they are also independent from your Windows user account, so you can add or remove a Linux user account without changing your Windows credentials.

Sudo is a special user group in Linux. Members of that group are allowed to run commands and apps as a root user (i.e. elevated). The sudo group is available when the sudo package is installed. Besides the group, it provides the sudo command, that should be used to elevated a command or app, e.g. $ sudo vim /etc/default/keyboard.

Find Users Included to Sudo

First of all, you might be interested in learning which user accounts in your WSL distro are permitted to use the sudo command.

  1. Run your WSL Linux distro, e.g. Ubuntu.Windows 10 WSL Run As User 1
  2. Type the following command and hit the Enter key: grep sudo /etc/group| cut -d: -f4.Windows 10 WSL Find Sudo Users

The cut command extracts values for column #4  from the /etc/group file, that contains everything related to groups in Linux. It is delimited by ":". The grep command prints only the line that contains the 'sudo' line.

It is worth noting that in certain distros, the sudo command might be configured to use any other group instead of the 'sudo' group. For example, in Arch Linux, members of the 'wheel' group are allowed to use sudo. There is no 'sudo' group in this distro. In such a case, take a look at the /etc/sudoers file, and read its man page (run $ man sudoers).

Tip: You can list groups a user account included to with the groups <username> command. E.g.

$ groups winaero

Windows 10 WSL Find Groups For User

To Add a User to Sudo in WSL Linux in Windows 10

  1. Run your WSL Linux distro, e.g. Ubuntu, under the root user or the user that is already allowed to use sudo.
  2. Type the command: sudo usermod -a -G sudo <username>. Substitute <username> in the command with the actual user account name you want to add to the sudo group.Windows 10 WSL Add User To Sudo
  3. Alternatively, you can use the following command: gpasswd -a <username> sudo. The result will be the same.

To Remove a User from Sudo in WSL Linux in Windows 10,

  1. Run your WSL Linux distro, e.g. Ubuntu, under the root user or the user that is already allowed to use sudo.
  2. Type the command: sudo gpasswd -d <username> sudo. Substitute <username> in the command with the actual user account name you want to remove from the sudo group.Windows 10 WSL Remove User From Sudo

That's it.

Related articles:

Driver Updater

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.