0

I migrated from Ubuntu-20 to Debian-12, and I can't excute the command sudo with my username my_name within a fresh installed system.

So, I added my_name into "sudo" group(usermod -aG sudo my_name) within a root logged-in terminal, and then rebooted my computer.

But it doesn't work, I still get the message like "my_name is not in sudoers file...".

I found a strange thing, i.e. when I issue groups command within a terminal window that logged-in as my_name, the "sudo" group name do NOT exist in the group list. But when I execute groups my_name with root's permission, the "sudo" group name DO EXIST in the group list!

Is this a bug of Debian-12? Or I missed some action?

9
  • not in sudoers file ... it states not in a file ... not a group - have a look in /etc/sudoers file and the /etc/sudoers.d folder Sep 12, 2023 at 2:39
  • 3
    FYI, when the installer asks you for root password, entering no password would instead configure sudo. Sep 12, 2023 at 2:42
  • 1
    @JaromandaX thx! I think that It's not necessary to explicitly add my_name into /etc/sudoers file, because there is an entry for all members of sudo group. Am I right?
    – Leon
    Sep 12, 2023 at 2:44
  • 2
    The fact that sudo appears in the output of groups yourusername but not groups suggests you've not logged out and back in after doing usermod -aG sudo my_name. Sep 12, 2023 at 5:15
  • 2
    @StéphaneChazelas what's puzzling me is that this conclusion doesn't tally with "and then rebooted my computer" Sep 12, 2023 at 13:50

4 Answers 4

1

Have the /etc/group and/or /etc/gshadow files been edited manually (outside usermod/groupmod and similar tools)?

There might be a syntax error that is small enough to be ignored by groups yourusername but the PAM libraries that set up your session might be more strict.

Run grpck as root to check the syntax of the group files.

You might want to run pwck too, although you are certain to get some error messages about system accounts like lp, news, uucp, list, irc and gnats not having a home directory; in most cases, that just means you don't have the respective subsystem/service installed, and is harmless.

0
0

1.Log in as root: You need to log in to the root account to be able to make changes to the sudoers file. If you have the root password, you can switch to the root user by typing su in the terminal and then entering the root password.

1.1 Find visudo at /usr/sbin.

1.2 Add /usr/sbin to your PATH: You can temporarily add /usr/sbin to your PATH like this:

export PATH=$PATH:/usr/sbin

1.3 Run visudo with full path:

/usr/sbin/visudo
  1. Edit the sudoers file: Once logged in as root, use the visudo command to safely edit the sudoers file. This command opens the sudoers file in the default text editor and checks for syntax errors upon saving, which is crucial since a mistake can lock out all sudo access.

  2. Add your user to the sudoers file: In the sudoers file, look for a line that looks like this:

root    ALL=(ALL:ALL) ALL

Below this line, add a line for your user account like so:

yourusername    ALL=(ALL:ALL) ALL

Replace yourusername with your actual username.

  1. Save and exit: After adding your user to the sudoers file, save the file and exit the editor. If you're using visudo with the default Vim editor, you can do this by typing :wq and then pressing Enter.

  2. Log out from root: Once your user has been added, log out from the root user and try using sudo with your regular user account.

1
  • export is unnecessary, and once you've added /usr/sbin to PATH, you don't need that prefix to run visudo; but otherwise a good answer, thankyou. Nov 13, 2023 at 3:53
0

Run su and sudo adduser user_name sudo to add the user into the sudo group as root. Reboot when done with /sbin/reboot. This was tested in a Debian 12 virtual machine in Virtualbox.

-1

I had the same problem: after giving user X root permission under root account, login back to user X and applying sudo results in "not in sudoers group" despite user can be seen with 'getent group sudo'.

Yet, one can change permissions as well under Gnome settings, Users and groups. That worked for me.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .