making sh script have root permmission
how to write sh script to have root permmission so that i can lauch apps which needs root permmission.
let say i want to launch kppp using sh script, but how can i script it to login as root and lauch kppp? |
The best way is to use sudo. In the script you put the command "sudo <command>". Then you edit /etc/sudoers to allow the command to be run. By default, you need to enter your own password (not root's) but this can be avoided. Take a look at the man pages for sudo and sudoers for more information.
Be cautious about making changes that allow non-root users to run root commands though. |
You could add something like this to the top of the script:
Code:
ROOT_UID=0 # Only users with $UID 0 have root privileges. [edit]Crap.. read your question wrong, you want to make it so the user has access.. my bad.. ;) Umm.. yeah, use sudo or just su to root. [/edit] |
i want to launch
# /usr/sbin/slmodemd --country=MALAYSIA /dev/slusb0 # kppp both of these command needs root permmission. i would like to make a sh script to do the both command above. how do i get the scirpt to have root permmission. |
Quote:
|
i dont know how to edit sudoer file.
how is the syntax? where can i get howto documentation for editing sudoer file? |
Quote:
The file itself includes some handy examples, e.g. %users ALL=/sbin/mount /cdrom,/sbin/umount /cdrom |
Quote:
Login as root, run "visudo" [techlaw@localhost techlaw]$ su Password: [root@localhost techlaw]# visudo You get a file that looks like this (I did anyway) # sudoers file. # # This file MUST be edited with the 'visudo' command as root. # # See the sudoers man page for the details on how to write a sudoers file. # # Host alias specification # User alias specification # Cmnd alias specification # Defaults specification # User privilege specification root ALL=(ALL) ALL There is more, but this is enough to get you started... Now use VI commands. This is what I did... move cursor, with the arrow keys, to the spot I want to edit -- "User privilege specification" section, press shift+r (Uppercase r) to get to REPLACE mode. Type this text on the next line after the root entry (using your login): your_user_name_here ALL=(ALL) NOPASSWD: ALL , then press (in this order): shift + : w ENTER shift + : q ENTER then test it out [techlaw@localhost techlaw]$ sudo redhat-config-network and the netconfig GUI started right up. Now this may not be the perfect or elegant way, but who cares? It got the job done. Hope I was some help, oklitig8r |
why should i used vi?
cant i use other text editor to edit sudoers.conf? |
Quote:
But, maybe, by reading the man and info pages, you can make some sense of how to do that and then share it with us. That way, we all learn something. ;) oklitig8r |
Sudoer
Lets say I have a user (ut-game20 who has a game server running on my box.
I want to give him permission to start svc -u /service/ut-game2 and also permission to stop his game server svc -d /service/ut-game2 Is this the correct entry I need to put in my sudoer file? ------------------------------------------------------------------------ # User alias specification # Cmnd alias specification # Defaults specification # User privilege specification root ALL=(ALL) ALL # Uncomment to allow people in group wheel to run all commands # %wheel ALL=(ALL) ALL # Same thing without a password # %wheel ALL=(ALL) NOPASSWD: ALL # Samples # %users ALL=/sbin/mount /cdrom,/sbin/umount /cdrom # %users localhost=/sbin/shutdown -h now ut-game1 svc -d /service/ut-game1 ut-game1 svc -u /service/ut-game1 ------------------------------------------------------------------------ |
All times are GMT -5. The time now is 06:24 AM. |