Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back > Forums > Linux Forums > Linux - General
User Name
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.


  Search this Thread
Old 09-09-2004, 08:06 PM   #1
LQ Newbie
Registered: Sep 2004
Posts: 4

Rep: Reputation: 0
how do I make sure that the user that is going to run the script is a root user???

I am writing a script that takes input from one file and processes it and then it redirercts the output to a different file.

Now my question is: How can I make sure that the user that is trying to run the script is a root user???

Any help would be greatly appreciated.
Old 09-09-2004, 09:04 PM   #2
Senior Member
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 58
You can add something like this to the top of the script...

# Ensure that root is running the script.
if [ $WHOAMI != "root" ]; then
echo "You must be root to add news users!"
exit 1
Old 09-10-2004, 02:06 AM   #3
LQ Newbie
Registered: Sep 2004
Posts: 4

Original Poster
Rep: Reputation: 0
thanks alot

That worked perfectly
Old 09-10-2004, 08:54 AM   #4
Registered: Jun 2004
Location: Britain
Distribution: Slackware
Posts: 186

Rep: Reputation: 31
chown root.root SCRIPT
chmod +s SCRIPT

this sets the suid bit

therefore when you run the program you are running it as root even is logged in as a user


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Do you run as root or user and why? aysiu Linspire/Freespire 7 10-04-2005 03:19 AM
allow sudo for www user to run root shell script cccc *BSD 12 07-23-2005 04:48 PM
How to run a Script as root, after Login as User, in GDM MHOOO Red Hat 14 03-08-2005 09:41 AM
I can not run X as root, only as user dtpmike Fedora 5 11-24-2004 05:45 PM
Run a script as a different user dtheorem Programming 5 11-05-2003 06:57 PM

All times are GMT -5. The time now is 02:46 PM.

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