Page 1 of 1

commenting specific string

Posted: 2020/03/10 02:35:34
by knzzz
Hi All,

i want to comment a line in sudoers file if the specific string is not present

%test ALL=(ALL) ALL

%testing ALL=(ALL) ALL

in the above line no password is not there means how to comment that specific line alone i want to comment testing line alone not the test line

REgards
Kanna

Re: commenting specific string

Posted: 2020/03/10 04:51:16
by afewgoodman
Hi,

if you want to comment testing line only,

%test ALL=(ALL) ALL

# %testing ALL=(ALL) ALL

Is it what you want?

BR.

Re: commenting specific string

Posted: 2020/03/10 08:48:43
by sml
I'm not quite sure I understand what you're trying to achieve.

Code: Select all

$ sudo sed -i '/^%testing\>/{/NOPASSWD:/!s/^/#/}' /etc/sudoers /etc/sudoers.d/*
Something like this?

Re: commenting specific string

Posted: 2020/03/10 18:16:09
by pjsr2
Avoid editing your /etc/sudoers file.

The design in CentOS is that you add your customization in files in the /etc/sudoers.d directory.
Your /etc/sudoers file could be replaced during package updates.

Files in the /etc/sudoers.d directory are '#include'-d near the end of the /etc/sudoers file.

Note that order in whatever you do in the sudo configuration files is important. If more than one line matches, the last one wins.

Re: commenting specific string

Posted: 2020/03/10 19:14:30
by TrevorH
Your /etc/sudoers file could be replaced during package updates.
That should not happen, it is marked as a config file in the rpm spec which means that if it has been altered, it will not be replaced.