How to solve "wsl is not in the sudoers file" on Ubuntu 24.04

Sometimes after change your Ubuntu WSL version, you will see this message:

wsl is not in the sudoers file

So, how to solve this:

First step - On PowerShell terminal, type this command:

wsl --list --verbose

Then you will go to identify the correct name of your disto. See:

PS C:\Users\uaigeek> wsl --list --verbose
  NAME            STATE           VERSION}
* Ubuntu          Stopped         2
  Ubuntu-20.04    Stopped         2
  Ubuntu-24.04    Stopped         2

On my case, the distro is Ubuntu 24.04, then the name is "Ubuntu-24.04"

Second step - Keep on the PowerShell terminal and use the next command to open your WSL distro as root. The command is:

wsl -d MY_DISTRO --user root

Or in my case

wsl -d "Ubuntu-24.04" --user root

Third step - Observe that your terminal became a bash (Linux terminal), then use the bellow command to add your user to sudo group. The command is:

usermod -aG sudo MY_USER

or in my case:

usermod -aG sudo uaigeek

Conclusion - The problem was solved, and you will be use the sudo and your correlates commands.

Reference:





Comentários

Postagens mais visitadas deste blog

SCP com porta diferente

Solução VAF da SEFMG com o erro "Não foi possível conectar ao servidor."

Conectividade social ICP travando. Solução do dia 20/092016