#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Location
    Inside the GNU/Hurd kernel
    Posts
    492
    Rep Power
    13

    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.
  2. #2
  3. No Profile Picture
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Location
    The Emerald City
    Posts
    289
    Rep Power
    13
    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
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Location
    Inside the GNU/Hurd kernel
    Posts
    492
    Rep Power
    13
    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?
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Posts
    465
    Rep Power
    14
    su -c foo.sh

    No arguments allowed, this should do it.
    Words must be weighed, not counted.
  8. #5
  9. Throws Rocks
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio
    Posts
    392
    Rep Power
    14

    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.
  10. #6
  11. Shes dancing (obviously)
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2002
    Location
    the far side
    Posts
    527
    Rep Power
    14
    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?
  12. #7
  13. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Posts
    465
    Rep Power
    14
    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!
    Words must be weighed, not counted.
  14. #8
  15. Shes dancing (obviously)
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2002
    Location
    the far side
    Posts
    527
    Rep Power
    14
    whats your ip? :P

    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?
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Location
    Inside the GNU/Hurd kernel
    Posts
    492
    Rep Power
    13
    Ehm..?

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

IMN logo majestic logo threadwatch logo seochat tools logo