commenting specific string

Issues related to applications and software problems
Post Reply
knzzz
Posts: 147
Joined: 2017/02/25 12:41:42

commenting specific string

Post by knzzz » 2020/03/10 02:35:34

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

afewgoodman
Posts: 94
Joined: 2019/12/11 03:51:58

Re: commenting specific string

Post by afewgoodman » 2020/03/10 04:51:16

Hi,

if you want to comment testing line only,

%test ALL=(ALL) ALL

# %testing ALL=(ALL) ALL

Is it what you want?

BR.

sml
Posts: 113
Joined: 2020/01/17 09:01:44

Re: commenting specific string

Post by sml » 2020/03/10 08:48:43

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?

pjsr2
Posts: 476
Joined: 2014/03/27 20:11:07

Re: commenting specific string

Post by pjsr2 » 2020/03/10 18:16:09

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.

User avatar
TrevorH
Forum Moderator
Posts: 28867
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: commenting specific string

Post by TrevorH » 2020/03/10 19:14:30

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.
CentOS 6 will die in November 2020 - migrate sooner rather than later!
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 is dead, do not use it.
Full time Geek, part time moderator. Use the FAQ Luke

Post Reply

Return to “CentOS 7 - Software Support”