LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-14-2008, 06:22 PM   #1
SirTristan
Member
 
Registered: Feb 2006
Distribution: GNU/Linux
Posts: 54

Rep: Reputation: 15
Granting root permissions to a bash script than can be run by a user?


How might I be able to grant root permissions to a bash script (such that the bash script can for instance execute root commands in /usr/sbin), but give a user permissions to execute this bash script? So thus, the user can execute the bash script, and the bash script can execute a /usr/sbin command as if it was root.

(BTW I'm aware this can be very dangerous)
 
Old 06-14-2008, 06:48 PM   #2
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
If I'm not too senile, scripts with SUID don't behave the same as binaries - basically SUID is not allowed. You can try to have a binary execute a script - I have no idea whether the script will run as intended though, or if privileges will be dropped because you're not really root.
 
Old 06-14-2008, 07:00 PM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Using Sudo is your only solution.
 
Old 06-14-2008, 07:57 PM   #4
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
suid works for scripts on some unix-likes OSes, but not Linux. This is for security reasons (see The Secure Programming for Linux and Unix HOWTO).

I believe sudo will do it. For example, if your script is:
Code:
/usr/local/sbin/myscipt
Add a line like this to your sudoers file (remember to use the visudo program to edit the sudoers file - do not edit it directly).
Code:
username ALL = NOPASSWD: /usr/local/sbin/myscript
(where username is the user name of the user who should be able to execute the script with root privileges.

By the way, you should be very careful about this. Scripts are easy to trick into doing the bidding of a malicious user (environment attacks for example).
 
Old 06-14-2008, 10:29 PM   #5
SirTristan
Member
 
Registered: Feb 2006
Distribution: GNU/Linux
Posts: 54

Original Poster
Rep: Reputation: 15
Thank you, that's a good solution

To execute the commands as root, in my bash script I put 'sudo -u root /path/to/command' for the commands and executed the bash script normally, and it worked.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Root user check in bash script doesn't work tawalker Programming 6 12-18-2011 03:06 AM
How can I have a script owned as root and run as root by a user: setuid? stickey bit? abefroman Linux - Newbie 9 04-19-2008 05:15 PM
How to run script of another user from root? sikandar Linux - Software 4 09-05-2007 03:42 AM
Getting bash script files to run as root user helptonewbie Programming 5 04-13-2007 09:09 PM
how do I make sure that the user that is going to run the script is a root user??? nikold01 Linux - General 3 09-10-2004 07:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:59 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