Sudors file

clR3vv

Registered
Long story But I need to change my sudoers file to not require a password and do this in a bash script. Every time I try I mess up something so I thought I would come here and ask.
 

Mikuro

Crotchety UI Nitpicker
Generally, you should use visudo to edit the sudoers file, since it does syntax validation and makes backups for you. If you want to automate this in a bash script (which seems kind of shady...), you can treat it like any text file, really. Just be sure you get the syntax right.

Something like this ought to work (NOT TESTED!):

Code:
echo "ALL	ALL = NOPASSWD: ALL" >> /etc/sudoers
(As root, naturally.)
 

clR3vv

Registered
"sudo echo "ALLALL = NOPASSWD: ALL" >> /etc/sudoers" that failed.. it is wrong syntax but in the file it says

"# This file MUST be edited with the 'visudo' command as root."
Idk how do that that in a script :/
 

ElDiabloConCaca

U.S.D.A. Prime
It sounds like you must use 'visudo', just as the error message says.

visudo is an interactive application for editing and verifying the data and integrity of the sudoers file. I don't know whether it can be scripted -- if it cannot be scripted, then you will not be able to use visudo to edit the sudoers file in a script... period.

What you could do is make a copy of the sudoers file, edit the copy of the sudoers file, use visudo to verify the contents of the copy of the sudoers file (the man page for visudo explains this in great detail), then use root access to overwrite the original sudoers file with the edited copy.

Idea stolen from here:

http://www.linuxquestions.org/questions/programming-9/edit-sudoers-by-script-645094/
 

Mikuro

Crotchety UI Nitpicker
The problem was that my code snippet had a tab in it, which didn't paste properly into Terminal. Make sure there's whitespace (a space will do, it doesn't need to be a tab) between the first two 'ALL's.

I just tested it, and it works for me.
 
Top