LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-24-2004, 12:09 PM   #1
demmylls
Member
 
Registered: Aug 2003
Location: AT
Distribution: Fedora Core 3
Posts: 404

Rep: Reputation: 30
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?
 
Old 02-24-2004, 12:38 PM   #2
iainr
Member
 
Registered: Nov 2002
Location: England
Distribution: Ubuntu 9.04
Posts: 631

Rep: Reputation: 30
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.
 
Old 02-24-2004, 01:07 PM   #3
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
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]

Last edited by trickykid; 02-24-2004 at 01:08 PM.
 
Old 02-25-2004, 02:11 PM   #4
demmylls
Member
 
Registered: Aug 2003
Location: AT
Distribution: Fedora Core 3
Posts: 404

Original Poster
Rep: Reputation: 30
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.
 
Old 02-25-2004, 02:26 PM   #5
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
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.
 
Old 02-27-2004, 10:49 AM   #6
demmylls
Member
 
Registered: Aug 2003
Location: AT
Distribution: Fedora Core 3
Posts: 404

Original Poster
Rep: Reputation: 30
i dont know how to edit sudoer file.
how is the syntax?
where can i get howto documentation for editing sudoer file?
 
Old 02-27-2004, 11:04 AM   #7
iainr
Member
 
Registered: Nov 2002
Location: England
Distribution: Ubuntu 9.04
Posts: 631

Rep: Reputation: 30
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
 
Old 03-08-2004, 04:28 PM   #8
oklitig8r
LQ Newbie
 
Registered: Jan 2004
Location: Tulsa, OK
Distribution: Fedora Core 1 - rh 2.4.22
Posts: 15

Rep: Reputation: 0
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
 
Old 03-09-2004, 10:41 AM   #9
demmylls
Member
 
Registered: Aug 2003
Location: AT
Distribution: Fedora Core 3
Posts: 404

Original Poster
Rep: Reputation: 30
why should i used vi?
cant i use other text editor to edit sudoers.conf?
 
Old 03-11-2004, 09:10 AM   #10
oklitig8r
LQ Newbie
 
Registered: Jan 2004
Location: Tulsa, OK
Distribution: Fedora Core 1 - rh 2.4.22
Posts: 15

Rep: Reputation: 0
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
 
Old 08-21-2004, 12:22 AM   #11
Jayco
LQ Newbie
 
Registered: Aug 2004
Posts: 1

Rep: Reputation: 0
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


------------------------------------------------------------------------
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
making a script run with root rights box_l Programming 12 02-10-2005 09:44 PM
Making a new script Lostboys Slackware 9 09-07-2004 06:11 AM
creating shell script that executes as root regardless of who runs the script? m3kgt Linux - General 13 06-04-2004 10:23 PM
vfat partition permmission problems demmylls Linux - General 2 02-24-2004 02:44 PM
cant set permmission demmylls Linux - General 1 11-25-2003 12:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration