amuck-landowner

Help with sed command

ricardo777

New Member
Hello,

Can someone help me with the following command:

sed -i -e "s/Defaults    requiretty/#Defaults    requiretty/g" /etc/sudoers

This will disable requiretty in the sudo file but when you run the command multiple times it adds an # every time the command runs.

Thank you.
 

NickM

New Member
Verified Provider
sed -i -e "s/^Defaults    requiretty/#Defaults    requiretty/g" /etc/sudoers

The ^ means to match starting at the beginning of a line.
 

ricardo777

New Member
Thank you very much.

I will now use:

grep -q "Defaults:username !requiretty" /etc/sudoers || echo "Defaults:username !requiretty" >> /etc/sudoers

Because this will add requiretty per user

Thank you for your help
 
Top
amuck-landowner