Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Find the answer to your Linux question:
New to Linux Forums? Register here for free!
    Linux Forums > GNU Linux Zone > Linux Programming & Scripting > running su from a bash script

Forgot Password?
 Linux Programming & Scripting   C, Perl, PHP, Bash Scripts, anything programming or script related post in here!

Site Navigation
Linux Articles
Linux Forums
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
RSS Feeds


Linux Forum Topics
Linux Forums
Your Distro
Linux Resources
GNU Linux Zone
The Community
Closed Thread
 
Thread Tools Display Modes
Old 12-27-2005   #1 (permalink)
Just Joined!
 
Join Date: Mar 2005
Location: cracow, poland
Posts: 76
running su from a bash script

hello

i'd like to write a script that would perform something as root but could be run by any user.
i've tried simply putting "su" into it but the script exits immediatel after i enter the password. "sudo" says i don't have the permission required.
how can i prompt for the root password, execute a root-only command and come back to the normal user from inside one script?
caminoix is offline  


Old 12-27-2005   #2 (permalink)
Trusted Penguin
 
Roxoff's Avatar
 
Join Date: Aug 2005
Location: Nottingham, England
Posts: 2,836
There are a couple of potential solutions here. You can use the sudo command so the users use 'sudo <bash_script>' to use the script, or you can set the ownership and sticky bit on the script so it always runs as root. For safety's sake you should use sudo.
__________________
Linux user #126863 - see http://counter.li.org/
Roxoff is offline  
Old 12-28-2005   #3 (permalink)
Linux Newbie
 
Join Date: Dec 2005
Posts: 104
Send a message via MSN to moonman89
Exclamation

Quote:
Originally Posted by Roxoff
There are a couple of potential solutions here. You can use the sudo command so the users use 'sudo <bash_script>' to use the script, or you can set the ownership and sticky bit on the script so it always runs as root. For safety's sake you should use sudo.

I may be wrong, but as far as im aware, you would also have to add the users into the sudoers file.
cheers,
Nathan
moonman89 is offline  
Old 12-28-2005   #4 (permalink)
Linux Enthusiast
 
Join Date: Aug 2005
Location: Hell
Posts: 514
Quote:
Originally Posted by Roxoff
or you can set the ownership and sticky bit on the script so it always runs as root. For safety's sake you should use sudo.
You mean the setuid bit. If your script is written properly, there should be no security problems with the setuid bit, since many system programs, like su, sudo, passwd, etc., all function using the setuid bit.
spoon! is offline  
Old 12-28-2005   #5 (permalink)
Linux Guru
 
Join Date: Oct 2001
Location: Täby, Sweden
Posts: 7,578
Quote:
Originally Posted by Roxoff
you can set the ownership and sticky bit on the script so it always runs as root.
That would be the SUID bit, not the sticky bit. However, that wouldn't work. For whatever strange reason, Linux only honors SUID/SGID on a.out and ELF files, not interpreted files...
Dolda2000 is offline  
Old 12-29-2005   #6 (permalink)
Linux Guru
 
anomie's Avatar
 
Join Date: Mar 2005
Location: Texas
Posts: 1,697
Quote:
For whatever strange reason, Linux only honors SUID/SGID on a.out and ELF files, not interpreted files...
Can't seem to locate a credible reference at the moment, but I remember reading that as of some kernel revision, support was dropped for the SUID bit on interpreted files (e.g. shell scripts).

The reason was/is that it is too difficult to harden these sufficiently.
anomie is offline  
Old 12-29-2005   #7 (permalink)
Linux Guru
 
anomie's Avatar
 
Join Date: Mar 2005
Location: Texas
Posts: 1,697
Quote:
... there should be no security problems with the setuid bit, since many system programs, like su, sudo, passwd, etc., all function using the setuid bit.
FWIW, the Bastille hardening program (http://www.bastille-linux.org/) recommends removing SUID bits even from a number of binaries, so they're definitely viewed as a security risk in some cases.
anomie is offline  
Old 01-13-2006   #8 (permalink)
Just Joined!
 
Join Date: Dec 2005
Location: Assam, India
Posts: 36
I am facing the same problem.

Even I need the solution of this.

I have written a shell script to find the system information. For viewing certain information, it needs root priviledge.

So instead of throwing an error message, instructing the user to run it as root, what I want is that it should ask for the root password and after the jobs done it should exit the root mode. Isn't there any way to do it?
mannahazarika is offline  
Old 01-13-2006   #9 (permalink)
Linux Engineer
 
Join Date: Nov 2004
Location: Ft. Polk, LA
Posts: 794
The best way is probably to set it up in sudoers and run it with sudo. Or I think the -c option to su allows you to run a command as the other user.
valan is offline  
Old 01-13-2006   #10 (permalink)
Just Joined!
 
Join Date: Nov 2005
Location: Nigeria
Posts: 2
Send a message via Yahoo to chuks
how will i configure suse on my system

[QUOTE=caminoix]hello

Hello Sir pls i am a beginger in linux,i have suse 9.0 now i installed it on my system but is not configured so have will i do the configuration on my system pls.You can send the spets to me with this E-mail address (chuksetunwa@yahoo.com)pls. sir.both the commands pls.

Thanks for helping me.
Yours friend Chuks.
chuks is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Free Magazines
Run Your Own Web Server Using Linux & Apache - Free 191 Page Preview
Learn about everything you'll need to build and maintain your Linux servers, and to deploy Web applications to them.
subscribe
Open Source Security Myths Dispelled
Dispel the five major myths surrounding Open Source Security and gain the tools necessary to make a truly informed decision for your IT organization
subscribe
InformationWeek
InformationWeek is the only newsweekly you'll need to stay on top of the latest developments in information technology.
subscribe



All times are GMT. The time now is 08:47 AM.






© 2000 - 2009 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.3.0 RC2