I am trying to write a simple bash file. One of the lines has sudo at the beginning which of course requires the user to input their sudo password. Is there a way to run the script without having to type in the sudo password?
I am trying to write a simple bash file. One of the lines has sudo at the beginning which of course requires the user to input their sudo password. Is there a way to run the script without having to type in the sudo password?
There is a way to add the script to the "sudoers" file so it won't prompt for a password to run the script. I am not sure of the syntax required for this.
The other method is to change the owner of the script so that root owns it, and then set the "setuid" flag on it. This means that the script will always run as the file's owner, i.e. root.
If you enable Advanced Permissions in Nautilus for the root user (gksudo gconf-editor; then apps > nautilus), then open a root file browser and get Properties for the script, you can change the owner and add the setuid ability.
I try to treat the cause, not the symptom. I avoid the terminal in instructions, unless it's easier or necessary. My instructions will work within the Ubuntu system, instead of breaking or subverting it. Those are the three guarantees to the helpee.
Depending on the situation (for example, if it's a script that has to run at boot or a cron script), you can remove the sudo because it is executed as root already.
Disclaimer: I am currently suffering from severe CSD (Compulsive Sarcasm Disorder).
My Site | Linux User #452328 | Running Arch Linux on Sony Vaio VGN-SZ61XN/C since October 2008
24 beers in a case, 24 hours in a day. Coincidence? I think not!
Trusty Tahr 64 bit, AMD Phenom II 955 Quad Core 3.2GHz, GeForce 9600 GT
16G PC2-6400 RAM, 128 GB SSD, Twin 1TB SATA 7200 RPM RAID0
I can give it a shot.
- Use Alt-F2 to open the Run dialog box.
- Type in "gksudo gconf-editor" (without the quotes) and press Enter.
- Enter your password (if necessary)
- Double click apps, scroll down and double-click nautilus, and then click preferences.
- In the right pane, scroll down until you see show_advanced_permissions. Put a checkmark in its box.
Now, any time you want to change the setuid of a file, run "gksudo nautilus" (using ALT-F2 again).
----
I personally think it would be easier for you to do it all in a terminal, since you obviously know bash. Just cd to the directory that has the file, and then run the following two commands
----Code:sudo chown root file sudo chmod ug+s file
Either way you choose, if you ever want to edit the file again, you'll have to open it as root. Run "gksudo gedit /path/to/file", either in a terminal, or with ALT-F2. (replace gedit with your favorite editor. In a terminal, you could also use sudo instead of gksudo.)
Last edited by trlkly; March 1st, 2009 at 07:58 PM. Reason: didn't close list
That's great everyone. Thank you so much for your help.
Bookmarks