How do I edit /etc/sudoers from a script?

后端 未结 12 791
花落未央
花落未央 2020-12-04 05:43

I need to edit /etc/sudoers from a script to add/remove stuff from white lists.

Assuming I have a command that would work on a normal file, how could I

12条回答
  •  自闭症患者
    2020-12-04 06:36

    Lots of answers, been working with sudo for yonks but did not have a need to automate the setup config till now. I used a mix of some of the answers above, writing my config line to the /etc/sudoers.d include location so i don't have to modify the main sudoers file, then checked that file for syntax , simple example below:

    Write your line to a sudoers include file:

    sudo bash -c 'echo "your_user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/99_sudo_include_file'
    

    Check that your sudoers include file passed the visudo syntax checks:

    sudo visudo -cf /etc/sudoers.d/99_sudo_include_file
    

提交回复
热议问题