How do I even give a user root privileges?

General support questions
Post Reply
r810628
Posts: 3
Joined: 2018/09/07 07:41:06

How do I even give a user root privileges?

Post by r810628 » 2018/09/07 07:47:15

Just started learning how to use both linux and centos.
I tried every method to give a user I created root privileges, such as...
- visudo -> username ALL=(ALL) ALL
- usermod -a -G wheel username
and more...
but I just couldn't get it to work...
Can someone please teach me how to do it?

User avatar
TrevorH
Site Admin
Posts: 33216
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: How do I even give a user root privileges?

Post by TrevorH » 2018/09/07 07:57:47

If you give someone sudo rights then they need to prefix their intended command with `sudo ...` - e.g. sudo usermod -a -G wheel username

And if you add a user to group wheel then the default configuration on CentOS 7 already allows them to run anything sudo so there's no need to add an entry specifically for their username.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

r810628
Posts: 3
Joined: 2018/09/07 07:41:06

Re: How do I even give a user root privileges?

Post by r810628 » 2018/09/07 19:42:12

TrevorH wrote:
2018/09/07 07:57:47
If you give someone sudo rights then they need to prefix their intended command with `sudo ...` - e.g. sudo usermod -a -G wheel username

And if you add a user to group wheel then the default configuration on CentOS 7 already allows them to run anything sudo so there's no need to add an entry specifically for their username.
Hi TrevorH,

I didn't know I had to prefix 'sudo' in order to use root command lines. Thanks for letting me know. However, I'm confused about the second paragraph you mentioned. Did you mean 'sudo' is not required if I add a user to group wheel?

User avatar
jlehtone
Posts: 4530
Joined: 2007/12/11 08:17:33
Location: Finland

Re: How do I even give a user root privileges?

Post by jlehtone » 2018/09/07 20:00:22

The 'sudo' (Do as SuperUser) is a command that executes other command as root.
E.g. "sudo foo" does (almost) same as if root had run "foo".

The 'sudo' is required.


There is "sudoers" configuration that sets, who can use the 'sudo'.
A default rule there says: all members of 'wheel' can use sudo.

When you did "usermod -a -G wheel username", the 'username' became able to sudo.
When you did "visudo -> username ALL=(ALL) ALL", the 'username' became able to sudo.

Now you have two rules that allow the user to sudo. One would be enough.


PS. The default config is in file /etc/sudoers. The 'visudo' edits that file.
Your command did add a line to that file. However, there is directory
/etc/sudoers.d for additional config files. The visudo can be told to use
such file.
(Additional sudo-rules can be in external databases, like LDAP.)

The benefit of separate file is that your custom rules are not inside a file that
might change when the sudo-package is updated.

r810628
Posts: 3
Joined: 2018/09/07 07:41:06

Re: How do I even give a user root privileges?

Post by r810628 » 2018/09/10 23:06:34

jlehtone wrote:
2018/09/07 20:00:22
The 'sudo' (Do as SuperUser) is a command that executes other command as root.
E.g. "sudo foo" does (almost) same as if root had run "foo".

The 'sudo' is required.


There is "sudoers" configuration that sets, who can use the 'sudo'.
A default rule there says: all members of 'wheel' can use sudo.

When you did "usermod -a -G wheel username", the 'username' became able to sudo.
When you did "visudo -> username ALL=(ALL) ALL", the 'username' became able to sudo.

Now you have two rules that allow the user to sudo. One would be enough.


PS. The default config is in file /etc/sudoers. The 'visudo' edits that file.
Your command did add a line to that file. However, there is directory
/etc/sudoers.d for additional config files. The visudo can be told to use
such file.
(Additional sudo-rules can be in external databases, like LDAP.)

The benefit of separate file is that your custom rules are not inside a file that
might change when the sudo-package is updated.
Thanks for the reply. Now I know the 'sudo' is always required unless I'm logging as root.
Also, I appreciate that you added useful information in P.S., but I don't get how this thing(sudoers/sudoers.d) works lol...

Post Reply