Sudo is not woking on my centos7

General support questions
Post Reply
nick70
Posts: 1
Joined: 2022/01/01 23:29:03

Sudo is not woking on my centos7

Post by nick70 » 2022/01/01 23:40:12

Happy new year every one!
I am new to this forum and know very little knowledge about the linux. I am trying to give a user to root permission to a user and try to run "visudo" but it isn't opening. Instead, it shows - starting ## sudoers allow particular users to run various commands as ## the root user, without needing the root password ... and ending ## Processes # Cmnd_Alias PROCESS = "/bin/nice, /bin/kill, /usr/bin/kill, /user/bin/killall .....

I can't find to give the permission as explained by many websites and forums.

## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL

Can somebody help me to solve this?
Thanks in advance for any help you are able to provide.

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

Re: Sudo is not woking on my centos7

Post by TrevorH » 2022/01/02 18:58:02

That sounds like exactly what visudo is meant to do. It puts you in edit, by default using vi, on the /etc/sudoers file and allows you to change it. When you save it after making your changes, visudo then syntax checks the new file and refuses to save it if there are any errors. This is why using visudo is the recommended tool as it will not let you save a non-working file that would then break users attempting to use sudo.

If using vi is not your cup of tea then you can choose what editor visudo uses - see man visudo for details of the ways in which you can do that. You can also Google for "vi cheat sheet" to get a lot of hits on how to use vi. I looked at one of them https://www.thegeekdiary.com/basic-vi-c ... eat-sheet/ and it seems to cover the basics.

Hint: what you say is the last line of the file is not the last line, it's just the last line displayed on your terminal, there are other pages below it.
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

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

Re: Sudo is not woking on my centos7

Post by jlehtone » 2022/01/03 06:59:08

Furthermore, the lines that you show
* The ones starting with # are comments. Documentation.
* The members of group 'wheel' can sudo. Add the account to group wheel, rather than edit sudoers.

See man usermod:
usermod -a -G wheel youraccount


One more thing,
do not edit the /etc/sudoers. Create a file in directory /etc/sudoers.d with visudo.
visudo -f /etc/sudoers.d/myrules

The thing is that /etc/sudoers is from the sudo package and could receive updates.
If you edit that file, then you have to merge those updates into your modified copy; package manager can't do the merge.
The separate files in /etc/sudoers.d/ stay neatly separate.

Post Reply