Linux Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsLinux Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old September 18th, 2002, 11:05 AM
Tuxie Tuxie is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Inside the GNU/Hurd kernel
Posts: 492 Tuxie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 1 m
Reputation Power: 7
Run script as root without typing root password?

I have a shell script that I need to execute as root,but since I have to execute the script often (the script loads my modem drivers and makes the connection),I was wondering if I could start it as root,but without typing the root password.I also have some extra users,which I want to be able to make an internet connection,but I dont want to give them the root password (they are Linux/computer newbies,so it doesnt have to be really secure ).Someone told me that I should use Sudo,but I dont know how I can do this.Btw,"man sudo" didnt really help
Thanks in advance.

Reply With Quote
  #2  
Old September 18th, 2002, 11:57 AM
justice41 justice41 is offline
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: The Emerald City
Posts: 289 justice41 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
You can run the script as setuid root, which effectively runs the script as if it were run by the superuser. Read the setuid man page for more info. Here's how to modify it
Code:
$ chown root yourscript.sh
$ chmod 4755 yourscript.sh

You change the owner to root and then set the setuid bit (the 4) so that when the program executes it runs under the uid of it owner (root) rather than the person that executed it.

Do not allow write permission for anyone except root. Also, be careful about any input that the script takes from the users, you don't want them running arbitrary code with root permissions.

jaa

Reply With Quote
  #3  
Old September 18th, 2002, 01:36 PM
Tuxie Tuxie is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Inside the GNU/Hurd kernel
Posts: 492 Tuxie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 1 m
Reputation Power: 7
Thanks for the info,but I probably did something wrong,because when i run the script I get the same errors as I did before when i ran it as a normal user,like:
"...I'm sorry, I didn't find your ADSL modem!
Tips: check that you are running this program as root and your device is seen by Linux by checking /proc/bus/usb/devices..."

I openend a root konsole,change the dir to /usr/bin/ and executed:
chown root adsl-start
chmod 4755 adsl-start
Then I rebooted to check if it worked,but I got the same errors.
The stuff that is inside the script needs root permission,so I need to execute it as root,are you sure that this does that?

Reply With Quote
  #4  
Old September 18th, 2002, 08:03 PM
riv's Avatar
riv riv is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Posts: 463 riv User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 37 m 50 sec
Reputation Power: 8
su -c foo.sh

No arguments allowed, this should do it.
__________________
Words must be weighed, not counted.

Reply With Quote
  #5  
Old September 18th, 2002, 10:46 PM
GNUbie's Avatar
GNUbie GNUbie is offline
Throws Rocks
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2002
Location: Cincinnati, Ohio
Posts: 392 GNUbie User rank is Corporal (100 - 500 Reputation Level)GNUbie User rank is Corporal (100 - 500 Reputation Level)GNUbie User rank is Corporal (100 - 500 Reputation Level)GNUbie User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 6 h 31 m 7 sec
Reputation Power: 8
sudo

You could add yourself to the sudoers file, then just use sudo.
To add yourself to the file:

Code:
bash# visudo



An example for root should already be listed, just follow suit.
From there, when you need to run your script:

Code:
bash$ sudo /usr/bin/adsl-start
__________________
Two things have come out of Berkeley, Unix and LSD.
It is uncertain which caused the other.

Reply With Quote
  #6  
Old September 19th, 2002, 11:11 AM
StealthElephant's Avatar
StealthElephant StealthElephant is offline
Shes dancing (obviously)
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jul 2002
Location: the far side
Posts: 526 StealthElephant User rank is Corporal (100 - 500 Reputation Level)StealthElephant User rank is Corporal (100 - 500 Reputation Level)StealthElephant User rank is Corporal (100 - 500 Reputation Level)StealthElephant User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 h 14 m 22 sec
Reputation Power: 8
the first thing su -c does is ask for a password.....
__________________

microsofts butterfly is their way off telling u their systems have a **** load of buggs
Advocating Linux Guide
Lesbian Linux
Great & Practical Computer Books

like the links?

Reply With Quote
  #7  
Old September 19th, 2002, 01:25 PM
riv's Avatar
riv riv is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Posts: 463 riv User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 37 m 50 sec
Reputation Power: 8
That's true, I don't use a password for my root account (hu ho said too much!!) so it works for me.

Or one could try to cmd < password if it works from a function otherwise write yet another script that will do it!

Reply With Quote
  #8  
Old September 20th, 2002, 05:24 PM
StealthElephant's Avatar
StealthElephant StealthElephant is offline
Shes dancing (obviously)
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jul 2002
Location: the far side
Posts: 526 StealthElephant User rank is Corporal (100 - 500 Reputation Level)StealthElephant User rank is Corporal (100 - 500 Reputation Level)StealthElephant User rank is Corporal (100 - 500 Reputation Level)StealthElephant User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 h 14 m 22 sec
Reputation Power: 8
whats your ip? :P

Reply With Quote
  #9  
Old September 20th, 2002, 05:31 PM
Tuxie Tuxie is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Inside the GNU/Hurd kernel
Posts: 492 Tuxie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 1 m
Reputation Power: 7
Ehm..?

Anyways,I works now with Sudo.I added this to my sudoers file:
tuxie ALL=NOPASSWD:/usr/bin/adsl-start

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsLinux Help > Run script as root without typing root password?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway