Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: sudo password

  1. #1
    Join Date
    May 2008
    Location
    Greece
    Beans
    6
    Distro
    Ubuntu 8.04 Hardy Heron

    sudo password

    Hi all!

    I was wandering if there is any way of inserting the user password
    inside a sudo command, using an option [-something] for example, and thus not having to type it when prompted to(after the sudo command)...
    Well,what I want to do is run a script at startup which would mount
    one of my hard drives that is not mounted automatically and mount must be executed as root, so a sudo is needed...

  2. #2
    Join Date
    May 2008
    Location
    Down the mousey hole.
    Beans
    135
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: sudo password

    If you could do it that way, anyone who can see your screen (physically or via a remote session) immediately sees your root password. Double-plus ungood.
    <:3~~~

  3. #3
    Join Date
    May 2008
    Location
    Greece
    Beans
    6
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: sudo password

    That would indeed be a problem but let's say we don't care about that that much.. I am looking into other ways of mounting the disk at startup but I would like to make the script work(just for fun )

  4. #4
    Join Date
    May 2008
    Location
    Down the mousey hole.
    Beans
    135
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: sudo password

    Oh, simple--instead of manually mounting it, add it to your fstab file. Instructions are here.
    <:3~~~

  5. #5
    Join Date
    May 2008
    Location
    Down the mousey hole.
    Beans
    135
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: sudo password

    Quote Originally Posted by Mr A Mouse View Post
    Oh, simple--instead of manually mounting it, add it to your fstab file. Instructions are here.
    Edited to add: Sudo was deliberately designed to not accept a password as an argument, so I don't think it can be done on a single command line. Doing it from a script may be possible, but I'm not good enough with scripts to know for sure.
    <:3~~~

  6. #6
    Join Date
    May 2008
    Beans
    4

    Re: sudo password

    Edit your sudoers file with visudo and add the NOPASSWD flag for the user for those commands you want to script.

    https://help.ubuntu.com/community/Sudoers

    However, why not run it as an init script?

    https://help.ubuntu.com/community/UbuntuBootupHowto
    Last edited by da chicken; May 17th, 2008 at 12:02 AM.

  7. #7
    Join Date
    Jan 2008
    Beans
    4,757

    Re: sudo password

    Is the hard-drive removeable?
    If so, you can use pmount without the sudo command to mount it.

    To test it, unmount the hard-drive and type in:
    Code:
    pmount /dev/sda1
    Or whatever the device name is called.

    Also, the bootscript is executed as root. So no sudo is required.

    Code:
    gksu gedit /etc/gdm/PreSession/Default
    Scroll all the way down to the bottom, and before the "exit 0" line.
    Put in this:
    Code:
    [ "$(ls -A /media/MOUNTPOINT)" ] && echo "device mounted" || mount /dev/DEVICE /media/MOUNTPOINT
    Change everything in bold to what they should be.

    Then save the file and reboot.

    NOTE:
    For the script to work, the folder where your hard-drive mounts in must be empty as a prerequisite.

    Regards
    Iain
    Last edited by ibuclaw; May 16th, 2008 at 11:54 PM.

  8. #8
    Join Date
    May 2008
    Location
    Down the mousey hole.
    Beans
    135
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: sudo password

    Quote Originally Posted by da chicken View Post
    Edit your sudoers file with visudo and add the NOPASSWD flag for the user for those files.

    https://help.ubuntu.com/community/Sudoers
    Oops! My bad--I didn't know you could do this.
    <:3~~~

  9. #9
    Join Date
    Jan 2008
    Beans
    4,757

    Re: sudo password

    Quote Originally Posted by da chicken View Post
    Edit your sudoers file with visudo and add the NOPASSWD flag for the user for those files.

    https://help.ubuntu.com/community/Sudoers
    But first, type in this:
    Code:
    export EDITOR=gedit
    sudo -E visudo
    Else you'll get a real shock when you open up into Vim!

    [EDIT]
    Just read the help docs... They are quoting me from a post I may last month!
    gedit ~/.bashrc

    Add the lines :

    export EDITOR=gedit
    alias visudo='-E visudo'
    That has made my day!
    Although, I have to shamefully say that that doesn't seem to work anymore (I'm looking in a fix).


    Regards
    Iain
    Last edited by ibuclaw; May 17th, 2008 at 12:10 AM.

  10. #10
    Join Date
    May 2008
    Location
    Greece
    Beans
    6
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: sudo password

    Quote Originally Posted by Mr A Mouse View Post
    Edited to add: Sudo was deliberately designed to not accept a password as an argument, so I don't think it can be done on a single command line. Doing it from a script may be possible, but I'm not good enough with scripts to know for sure.
    Well the script seems to run at startup but(I think because of the sudo) mount fails(I am not even prompted to enter a password...)

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •