[SOLVED] Cannot add default user to sudoers file

RazorEdge

New Member
Joined
Mar 10, 2022
Messages
23
Reaction score
3
Credits
216
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
 


MattWinter

Active Member
Joined
Dec 5, 2022
Messages
149
Reaction score
190
Credits
1,084
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?
 

Condobloke

Well-Known Member
Joined
Apr 30, 2017
Messages
6,086
Reaction score
5,081
Credits
38,407
Code:
sudo su

?
 

osprey

Well-Known Member
Joined
Apr 15, 2022
Messages
675
Reaction score
562
Credits
6,306
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.
 

wizardfromoz

Administrator
Staff member
Gold Supporter
Joined
Apr 30, 2017
Messages
8,618
Reaction score
7,573
Credits
35,206

sphen

Well-Known Member
Joined
Dec 12, 2022
Messages
600
Reaction score
542
Credits
6,933
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:
OP
R

RazorEdge

New Member
Joined
Mar 10, 2022
Messages
23
Reaction score
3
Credits
216
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!
 

arochester

Moderator
Staff member
Gold Supporter
Joined
Apr 25, 2017
Messages
1,721
Reaction score
1,389
Credits
3,694
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."

 

craigevil

Well-Known Member
Joined
Feb 24, 2021
Messages
419
Reaction score
419
Credits
2,889

Tolkem

Well-Known Member
Joined
Jan 6, 2019
Messages
1,516
Reaction score
1,245
Credits
11,069
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.
 

sphen

Well-Known Member
Joined
Dec 12, 2022
Messages
600
Reaction score
542
Credits
6,933
Removed to avoid distracting or hijacking the thread. See post #14, below.
-> Please do not reply or comment to this post.
 
Last edited:

forester

Well-Known Member
Joined
Mar 5, 2022
Messages
544
Reaction score
316
Credits
3,829
re: groups --
make sure the group "wheel" is uncommented in sudoers config file and add your user to the wheel group, as a suggestion.
 

wizardfromoz

Administrator
Staff member
Gold Supporter
Joined
Apr 30, 2017
Messages
8,618
Reaction score
7,573
Credits
35,206
@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:

wizardfromoz

Administrator
Staff member
Gold Supporter
Joined
Apr 30, 2017
Messages
8,618
Reaction score
7,573
Credits
35,206
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
 
MALIBAL Linux Laptops

Linux Laptops Custom Built for You
MALIBAL is an innovative computer manufacturer that produces high-performance, custom laptops for Linux.

For more info, visit: https://www.malibal.com

Members online


Latest posts

Top