Fix `username is not in Sudoers file. This event will be reported on Debian

This article explains how to “fix” sudo that cannot be used on Linux, so this message appears when trying to use it: “Your username is not in the sudoers file. This event will be reported.” On Debian (and Debian based Linux distribution Version, such as Ubuntu). sudo allows the system administrator to execute commands as root (administrator) or another user.

New Debian 10 (10.1) Buser installation example, where sudo does not work:

$ sudo apt update
[sudo] password for logix:
logix is not in the sudoers file.  This incident will be reported.

In a Fresh Debian installation, sudo does not work by default, because your username is not automatically added to the sudo group (by default, it works on Ubuntu). However, if you created a new user and forgot to add it to the sudo group, or another user in the system deleted the username from the sudo group, you might also see this message.
You can use to check if the currently logged in user belongs to the sudo group. groups command. in case groups Command does not return sudo On Debian-based Linux distributions, the username cannot be run using the following command sudo. Example output from a Debian user who is not in the sudo group:

$ groups
logix cdrom floppy audio dip video pugdev netdev scanner lpadmin

You might like: How to install the latest Firefox (Non-ESR) on Debian 10 Buster (stable) or Bullseye (beta)
The solution was to add the user to the sudo group. But how do you get root privileges in this case, because you cannot modify or add users as normal users? Adopt su - (Either sudo su -) And then add the user to the sudo group.
So to get root, then add your user to sudo Group, use:

su -
usermod -aG sudo YOUR_USERNAME
exit

where:

  • su Switch to root user while - Run a login shell, something like this /etc/profile, .bashrc, And so on (such a command usermod Will be in yours $PATH, So you do n’t have to type the full path to the executable). You can also use sudo su - Instead su -
  • You need to replace YOUR_USERNAME With the username you want to add to the sudo group.
  • I used usermode Add a group to an existing user as it can be used on any Linux distribution. adduser Either useradd Can also be usedadduser USERNAME -G sudo), But they may not work on all Linux distributions. Even if this article is for Debian, I hope to be able to use it in other Linux distributions (I noticed adduser Not applicable to Solus OS).
  • exit Because the root shell exists, you can run the command again as a normal user.

After this, sudo still doesn’t work! You will need to log out from that user, then log back in, and then sudo will work.
This fixes the issue that “username is not in the sudoers file. This event will be reported” on Debian machines, but in some cases you may run into another problem-sudo is not installed at all by default. This is the case, for example, in the smallest Debian installation. In this case, when you try to run the command using sudo, you see an error similar to the following:

$ sudo apt update
bash: sudo: command not found

In this case, please install sudo On Debian:

su - #or 'sudo su -'
apt install sudo
exit

You might like some articles about Debian:

  • How to downgrade a package to a specific version using Apt in Debian, Ubuntu or Linux Mint
  • How to display the history of packages that have been installed, upgraded or removed in Debian, Ubuntu or Linux Mint [dpkg]
  • How to list all packages in a repository on Ubuntu, Debian or Linux Mint [APT]
  • How to find packages (installed or not installed) that provide files on Ubuntu, Debian or Linux Mint

Source

Sidebar