LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
Search this Thread
Old 04-11-2009, 07:49 AM   #1
halfpower
Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 199

Rep: Reputation: 30
Two scripts, one runs with sudo the other only runs as root


I have two scripts. This one will run when I type "sudo script_file_name"

Code:
#!/bin/sh

mount /dev/sdb3 /mnt/sdb3 -t ntfs -o umask=0222
This one will not run when I type "sudo script_file_name," but it will run when I am root.
Code:
#!/bin/sh

shutdown now -h
Do you know what would cause this? All I'm really trying to do is to poweroff without being root.

Last edited by halfpower; 04-11-2009 at 10:04 AM. Reason: fix title
 
Old 04-11-2009, 08:00 AM   #2
GazL
Senior Member
 
Registered: May 2008
Posts: 3,502

Rep: Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024
Without any more detail then I'd guess it's either file permissions or a difference in the $PATH.
What are you seeing? Command not found? Permission denied? or something else?
 
Old 04-11-2009, 08:12 AM   #3
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,118

Rep: Reputation: 818Reputation: 818Reputation: 818Reputation: 818Reputation: 818Reputation: 818Reputation: 818
shutdown can only be executed by UID 0 and GID 0 (which is root's userid). If you really, really what to be able to shut the system down without using su to do it, you can change the owner and group of your shell program to root and change the mode to 4755 (you must do this as root). You could also use the init utility instead of the shutdown utility in your shell program; i.e.,
Code:
#!/bin/sh
#
# non-root user system shutdown
#
/sbin/init 0
Bear in mind that either is not a real good idea when you can simply
Code:
su -
Password: root-password
init 0
Although you can do something (like set the so-called "su" bit, which is what mode 4755 does) it can come back and bite you; there is a reason that certain commands require root permission to be used and you should think it through before you jump off this cliff.
[EDIT]
Well, ignorant me (here's one of those things that won't port from Solaris). Thanks to gazl for pointing out that SUID doesn't work in Linux (and, dang it, that's a good thing, too).

Sigh.

Last edited by tronayne; 04-11-2009 at 09:31 AM.
 
Old 04-11-2009, 09:09 AM   #4
GazL
Senior Member
 
Registered: May 2008
Posts: 3,502

Rep: Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024
Quote:
Originally Posted by tronayne View Post
If you really, really what to be able to shut the system down without using su to do it, you can change the owner and group of your shell program to root and change the mode to 4755 (you must do this as root).
SUID is ignored on shell scripts under linux, so this won't work.
 
Old 04-11-2009, 09:22 AM   #5
wadsworth
Member
 
Registered: Aug 2007
Distribution: Slackware64 13.37
Posts: 215

Rep: Reputation: 65
Supply the full path to shutdown in your script
Code:
sudo /sbin/shutdown -h now
then use visudo to allow you user (or group) to execute /sbin/shutdown.
 
Old 04-11-2009, 09:58 AM   #6
rg3
Member
 
Registered: Jul 2007
Distribution: Slackware Linux
Posts: 514

Rep: Reputation: Disabled
I don't think the above posts hit the nail in the head (but some of them are very close). The second script probably doesn't run because you are using "shutdown" as the command to run, and shutdown resides in /sbin, which is probably not in your user's PATH. Probably changing "shutdown" for "/sbin/shutdown" should do the trick.

Also, the reason the SUID bit in scripts "doesn't work" is that in Unix there is a distinction between the owner's UID for the process and the effective UID. When you set the setuid bit in a program, you change the effective UID to the one of the user owning the file, but now the owner's UID of the process, which continues to be your normal user. Problem: when a process forks (to launch another process), the owner and effective UID are inherited from the owner UID of the parent process. Hence, any program launched from a shell script that has the setuid bit is launched as the normal user, and not as the effective UID user.
 
Old 04-11-2009, 10:19 AM   #7
halfpower
Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 199

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by GazL View Post
Without any more detail then I'd guess it's either file permissions or a difference in the $PATH.
What are you seeing? Command not found? Permission denied? or something else?
It says:
Code:
me@computer~$ sudo turnoff
/usr/local/bin/turnoff: line 3: shutdown: command not found
 
Old 04-11-2009, 10:52 AM   #8
GazL
Senior Member
 
Registered: May 2008
Posts: 3,502

Rep: Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024
It's probably the $PATH then. Change your script to run /sbin/shutdown as wadsworth suggested above and it should work.
 
Old 04-11-2009, 05:05 PM   #9
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,211

Rep: Reputation: 293Reputation: 293Reputation: 293
Are you in the power group?

Output of 'groups' please.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to write a batch file for windows that starts cygwin tool and runs unix scripts plasya777 Programming 5 05-04-2009 08:53 AM
LimeWire only runs as root Ipsofacto Suse/Novell 5 01-19-2006 02:59 AM
Mozilla (1.7) only runs in root. epheles Linux - Newbie 4 01-09-2005 12:05 PM
x only runs in root Bigfut Red Hat 1 08-19-2004 03:43 AM
Eterm 0.9.2 runs only as root! Mysterious Alan Slackware 3 09-30-2003 12:35 AM


All times are GMT -5. The time now is 01:51 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration