LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   making sh script have root permmission (https://www.linuxquestions.org/questions/linux-general-1/making-sh-script-have-root-permmission-149988/)

demmylls 02-24-2004 12:09 PM

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?

iainr 02-24-2004 12:38 PM

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.

trickykid 02-24-2004 01:07 PM

You could add something like this to the top of the script:

Code:

ROOT_UID=0      # Only users with $UID 0 have root privileges.
NOTROOT=67      # Non-root exit error.

if [ "$UID" -ne "$ROOT_UID" ]
then
  echo "Only ROOT Can Run This."
  exit $NOTROOT
fi

This will tell the user if they are not root that they need to be root in order to run the script.

[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]

demmylls 02-25-2004 02:11 PM

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.

trickykid 02-25-2004 02:26 PM

Quote:

Originally posted by demmylls
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.

You can't, kppp is not a script, its binary. Your probably better off changing the permissions to execute or just setup and use sudo.

demmylls 02-27-2004 10:49 AM

i dont know how to edit sudoer file.
how is the syntax?
where can i get howto documentation for editing sudoer file?

iainr 02-27-2004 11:04 AM

Quote:

Originally posted by demmylls
i dont know how to edit sudoer file.
how is the syntax?
where can i get howto documentation for editing sudoer file?

Type "man sudoer". The man page is pretty intimidating but if you go to the end you'll see quite a few examples that should help.

The file itself includes some handy examples, e.g.

%users ALL=/sbin/mount /cdrom,/sbin/umount /cdrom

oklitig8r 03-08-2004 04:28 PM

Quote:

Originally posted by demmylls
i dont know how to edit sudoer file.
how is the syntax?
where can i get howto documentation for editing sudoer file?

Open a shell. -- [techlaw@localhost techlaw]$

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

demmylls 03-09-2004 10:41 AM

why should i used vi?
cant i use other text editor to edit sudoers.conf?

oklitig8r 03-11-2004 09:10 AM

Quote:

Originally posted by demmylls
why should i used vi?
cant i use other text editor to edit sudoers.conf?

You can use any text editor you want. vi happens to be the default editor. However, to use a different editor, you need to configure the EDITOR environment variable and I haven't figured out how to do that, yet.

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

Jayco 08-21-2004 12:22 AM

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.