[SOLVED] Cannot add default user to sudoers file

RazorEdge

New Member
Joined
Mar 10, 2022
Messages
29
Reaction score
4
Credits
275
Hey guys,

I'm trying to give my default user account (named tim) sudo privileges on Debian 11 but I seem unable to. I've run the command as root:

Bash:
usermod -a -G sudo tim

My account appears to be in the sudoers file (see below), but when I attempt to access sudo privileges I'm unable to. Can anyone help? The only issue I can think of is my account name may not be tim.

Screenshot.jpg
 


Maybe some of the other guys can confirm, but I don't think adding to sudo group just works. I think it has to be treated specially by adding the user to the sudoers file by using sudoedit. Have you tried that?
 
Code:
sudo su

?
 
The error message is describing the problem: tim is not in the sudoers file. So as root, you can write "tim" to either /etc/sudoers, or create a file in /etc/sudoers.d/. You can use the visudo command to write to such files, e.g.: visudo /etc/sudoers, or visudo /etc/sudoers.d/timsfile, and include the line:
Code:
tim    ALL=(ALL:ALL) ALL
Then log out and log in.
 
I doubt this is a solution, but it should be checked. Did someone edit the sudo configuration in /etc/sudoers?

On my Debian 11 servers, the /etc/sudoers file is a copy of what I see when I use the command "visudo" to edit the sudo'ers list. In it, there is an entry that gives the sudo group its sudo privileges. It was there in the default sudoers file at installation time; I did not add it myself.

Run "sudo visudo" (or "visudo" as root). (You might also try "more /etc/sudoers" to see it.) Is there a line that gives privileges to the sudo group? The percent sign indicates group rather than a specific user. Look for this comment and setting:

Code:
# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

This is the setting that allows members of the group "sudo" to run on ALL hosts, as (ALL users : ALL groups), and run ALL commands with superuser privileges.
 
Last edited:
Thanks for the help guys. Would you be able to give me more specific instructions to create a file in /etc/studoers.d or modify the /etc/sudoers file? I get how to use visudo but don't know exactly what to modify.

I've also come across these instructions from the Linux Foundation's Introduction to Linux course:


Now, you need to create a configuration file to enable your user account to use sudo. Typically, this file is created in the /etc/sudoers.d/ directory with the name of the file the same as your username. For example, for this demo, let’s say your username is student.

After doing step 1, you would then create the configuration file for student by doing this:


Bash:
# echo "student ALL=(ALL) ALL" > /etc/sudoers.d/student

Finally, some Linux distributions will complain if you do not also change permissions on the file by doing:

Bash:
# chmod 440 /etc/sudoers.d/student


Will these instructions work if I replaced student with tim? The format seems to be slightly different to to what's been suggested, in particular this part - student ALL=(ALL) ALL.

Thanks!
 
wizardfromoz gave you a correct answer.

In Debian install if you create a Root password you will get a Root account and the User will not be added to sudo. If you DO NOT create a Root password, then Root defaults to the User who will be added to the sudo file. BUT the User can be added to sudo later.

"Now lets update, install sudo and grant sudo access to the default user.
apt-get update
If you don’t want to give sudo access to the users then you should skip these steps.
AS ROOT
apt-get install sudo
usermod -a -G sudo <username>
Now reboot the system.
Its just enough to logout/login and not necessary to reboot the system but I prefer to reboot the system.
Now as we have granted sudo access to the default user, we can now proceed to installing other packages."

 
Would you be able to give me more specific instructions to create a file in /etc/studoers.d or modify the /etc/sudoers file?
Here you go:
1. Launch the terminal and run the following command (as root):
Bash:
nano /etc/sudoers
2. Locate the line that reads
Code:
# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL
and add your user right below it:
Code:
# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL
tim     ALL=(ALL:ALL) ALL
3. Save your changes (press CTRL + O, then hit enter) and close nano (press CTRL + x)
4. I can't remember whether you have to, but to be on the safe side, log out and back in. Then try running a command with sudo again and check that it works.
 
Removed to avoid distracting or hijacking the thread. See post #14, below.
-> Please do not reply or comment to this post.
 
Last edited:
Add User to sudoers list in Debian
Code:
su root
then
Code:
sudo usermod -aG sudo username

reboot
 
re: groups --
make sure the group "wheel" is uncommented in sudoers config file and add your user to the wheel group, as a suggestion.
 
@Condobloke on #3

Code:
sudo su
?

... can't be used because it requires the input by the OP of his ordinary user sudo password, which is not recognised in the sudoers file. Catch 22.

I'll sit back and watch, as I would back the knowledge of @arochester and others on Debian over mine any day of the week and twice on Sundays.

Avagudweegend all

Wiz
Edited out comment on another Post, now removed.
 
Last edited:
IX0LgkU.gif

You're not the only one, we failed to ask.

If you like, you can go to #1 and edit the Title to include a [SOLVED] at the beginning.

Enjoy your Linux. :)

Wizard
 


Top