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

后端 未结 12 792
花落未央
花落未央 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:23

    This worked for me based off what others posted here. When i used other peoples script it would open visudo for me but would not make the edit. This made the edit i needed to allow all users, including standard users, to install java 7u17 for safari/firefox.

    #!/usr/bin/env bash
    rm /etc/sudoers.new
    cp /etc/sudoers /etc/sudoers.new
    echo "%everyone   ALL = NOPASSWD: /usr/sbin/installer -pkg /Volumes/Java 7 Update 17/Java 7 Update 17.pkg -target /" >> /etc/sudoers.new
    cp /etc/sudoers.new /etc/sudoers
    

    This added the %everyone blah blah blah to the bottom of the sudoers file. I had to run the script like this.

    sudo sh sudoersedit.sh
    

    Good luck :D

提交回复
热议问题