Regex template for editing the / etc / sudoers file

I want to remove (uncommnet #) the wheel group in the / etc / sudoers file, so what would I use the Regex pattern that I should use?

#cat /etc/sudoers
....
....
## Allows members of the 'sys' group to run networking, software,
## service management apps and more.
# %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS

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

## Same thing without a password
# %wheel  ALL=(ALL)       NOPASSWD: ALL

....
....

I want to remove # from the next line.

...
# %wheel  ALL=(ALL)       NOPASSWD: ALL
...
+5
source share
2 answers

You should not edit the file with /etc/sudoersany kind of script. There is a reason for the team visudo. File editing sudoersshould be rare and well controlled.

If your editor for the command visudois vi, you can run something like this :%s/^# %wheel/%wheel/to uncomment all the lines starting with %wheel.

Or, if you think again that this is necessary:

sudo sed --in-place 's/^#\s*\(%wheel\s\+ALL=(ALL)\s\+NOPASSWD:\s\+ALL\)/\1/' /etc/sudoers

--in-place, . .

+15

:

sed -i 's/^#\s*\(%wheel\s*ALL=(ALL)\s*NOPASSWD:\s*ALL\)/\1/' /etc/sudoers
+3

All Articles