Shell Script with Superuser Power?
I want a shell script to have root privileges. I don't want it to ask for a password and I want the command line returned to the user who invoked the command without out superuser privileges and in the same shell that it was in before hand. I have the file
Code:
#!/bin/sh |
If you save this
Code:
#!/bin/sh Code:
ALL ALL = NOPASSWD: /usr/local/bin/start_wireless.sh Code:
sudo /usr/local/bin/start_wireless.sh Eric |
There are a couple of ways to do this. Off the top of my head you can do one of two things.
1) put the script in /usr/local/bin and then in the /etc/sudoers file all it root permissions without a password. Then when you invoke the script do sudo <script> and you will not get a password prompt 2) Set the setuid bit with the chmod command, I am sure what the exact options would be but maybe chmod 2755 <script> also I would check to make sure you are root before running the script put something like this in the first few lines of the script. Code:
if[ "$USER" != "root" ]; then |
*duplicate post*
|
Nice. 3 replies at the same time. You know something is interesting when...
regards, ...drkstr |
Quote:
Remember to make the script readonly for everyone by the way... I will leave it to your imagination as to the why. Also, setting the suid bit just like that, on a shell script, is unwise because that is inheritly dangerous. Eric |
Quote:
Eric |
Quote:
|
ahh. never tried it with a script...
i just add stuff like this to my rc.local but you are correct...even with suid the script does not inherit the privileges... |
Quote:
Code:
dagmar@scraps:~$ cat proof.sh |
the sticky bit is a completely different subject
|
I'm going to guess that the suid method wouldn't work because the script isn't being executed, it's invoking a seperate application then feeding it commands. Someone correct me if I'm wrong.
I recommend using sudo. There are numerous ways to configure sudo (the man page is over a thousand lines long) but the answer that Alien Bob provided should work great. |
Quote:
Shall be avoided at any costs. |
read the whole thread
|
Quote:
|
All times are GMT -5. The time now is 02:50 AM. |