|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
Run script as root without typing root password?
I have a shell script that I need to execute as root,but since I have to execute the script often (the script loads my modem drivers and makes the connection),I was wondering if I could start it as root,but without typing the root password.I also have some extra users,which I want to be able to make an internet connection,but I dont want to give them the root password (they are Linux/computer newbies,so it doesnt have to be really secure
).Someone told me that I should use Sudo,but I dont know how I can do this.Btw,"man sudo" didnt really help Thanks in advance. |
|
#2
|
|||
|
|||
|
You can run the script as setuid root, which effectively runs the script as if it were run by the superuser. Read the setuid man page for more info. Here's how to modify it
Code:
$ chown root yourscript.sh $ chmod 4755 yourscript.sh You change the owner to root and then set the setuid bit (the 4) so that when the program executes it runs under the uid of it owner (root) rather than the person that executed it. Do not allow write permission for anyone except root. Also, be careful about any input that the script takes from the users, you don't want them running arbitrary code with root permissions. jaa |
|
#3
|
|||
|
|||
|
Thanks for the info,but I probably did something wrong,because when i run the script I get the same errors as I did before when i ran it as a normal user,like:
"...I'm sorry, I didn't find your ADSL modem! Tips: check that you are running this program as root and your device is seen by Linux by checking /proc/bus/usb/devices..." I openend a root konsole,change the dir to /usr/bin/ and executed: chown root adsl-start chmod 4755 adsl-start Then I rebooted to check if it worked,but I got the same errors. The stuff that is inside the script needs root permission,so I need to execute it as root,are you sure that this does that? |
|
#4
|
||||
|
||||
|
su -c foo.sh
No arguments allowed, this should do it.
__________________
Words must be weighed, not counted. |
|
#5
|
||||
|
||||
|
sudo
You could add yourself to the sudoers file, then just use sudo.
To add yourself to the file: Code:
bash# visudo An example for root should already be listed, just follow suit. From there, when you need to run your script: Code:
bash$ sudo /usr/bin/adsl-start
__________________
Two things have come out of Berkeley, Unix and LSD. It is uncertain which caused the other. |
|
#6
|
||||
|
||||
|
the first thing su -c does is ask for a password.....
__________________
microsofts butterfly is their way off telling u their systems have a **** load of buggs Advocating Linux Guide Lesbian Linux Great & Practical Computer Books like the links? |
|
#7
|
||||
|
||||
|
That's true, I don't use a password for my root account (hu ho said too much!!) so it works for me.
Or one could try to cmd < password if it works from a function otherwise write yet another script that will do it! |
|
#8
|
||||
|
||||
|
whats your ip? :P
|
|
#9
|
|||
|
|||
|
Ehm..?
Anyways,I works now with Sudo.I added this to my sudoers file: tuxie ALL=NOPASSWD:/usr/bin/adsl-start |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > Linux Help > Run script as root without typing root password? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|