Results 1 to 9 of 9

Thread: Open Nautilus with SUDO abilities via script

  1. #1
    Join Date
    Sep 2013
    Beans
    57

    Open Nautilus with SUDO abilities via script

    Hi,

    I have been playing with a few scripts and want to make one to open nautilus as root when executed.

    So far I have used the code:

    echo mypassword | sudo | nautilus /

    this opens nautilus in the specified directory but doesnt give sudo premissions.

    yet in the terminal sudo nautilus / and entering the password will allow permission.

    I know it is not advisable to use this method however I would still like to know how it is done, if at all possible.

    Adam

  2. #2
    Join Date
    Sep 2006
    Beans
    8,627
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Open Nautilus with SUDO abilities via script

    You probably would do something like this:

    Code:
    gksu /usr/bin/nautilus
    But you might want to close it as soon as you are done so that you don't forget that it is running as root. Otherwise, things can get messy.

  3. #3
    Join Date
    Sep 2013
    Beans
    57

    Re: Open Nautilus with SUDO abilities via script

    Hi,

    Thanks for the quick response.

    This seems to still ask for the password.

    I would like to be able to execute the .sh file and have it open Nautilus without requesting the root password.

    Thanks.

  4. #4
    Join Date
    Sep 2006
    Beans
    8,627
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Open Nautilus with SUDO abilities via script

    Well to customize sudo, you have to edit sudoers.

    Code:
    %adam17  ALL=(ALL:ALL) /usr/bin/nautilus
    There's one more thing to change in that line but I'll leave you to figure that out.

  5. #5
    Join Date
    Aug 2012
    Location
    In front of the computer
    Beans
    159
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Open Nautilus with SUDO abilities via script

    Remember to edit sudoers with visudo instead of a regular text editor, it will check for errors after you finish editing, preventing you from rendering sudo useless on your system. If you don't want to use vi, you can pass any editor to visudo via the EDITOR variable, for ex. to use nano:
    Code:
    EDITOR=nano visudo

  6. #6
    Join Date
    Apr 2006
    Location
    Ubuntuland
    Beans
    2,124
    Distro
    Ubuntu 13.10 Saucy Salamander

    Exclamation Re: Open Nautilus with SUDO abilities via script

    Quote Originally Posted by Isamu715 View Post
    Remember to edit sudoers with visudo instead of a regular text editor, it will check for errors after you finish editing, preventing you from rendering sudo useless on your system. If you don't want to use vi, you can pass any editor to visudo via the EDITOR variable, for ex. to use nano:
    Code:
    EDITOR=nano visudo
    Don't put "visudo" in your EDITOR variable, just the name of the editor. visudo uses EDITOR to select your desired editor.
    24 beers in a case, 24 hours in a day. Coincidence? I think not!

    Trusty Tahr 64 bit, AMD Phenom II 955 Quad Core 3.2GHz, GeForce 9600 GT
    16G PC2-6400 RAM, 128 GB SSD, Twin 1TB SATA 7200 RPM RAID0

  7. #7
    Join Date
    Sep 2006
    Beans
    8,627
    Distro
    Ubuntu 14.04 Trusty Tahr

    visudo

    Quote Originally Posted by Slim Odds View Post
    Don't put "visudo" in your EDITOR variable, just the name of the editor. visudo uses EDITOR to select your desired editor.
    That's what that line does. When an environment variable precedes a program name, that variable is local to that program session. So in the example above EDITOR is set to nano just that once only for that particular session with visudo.

    Anyway, +1 to using visudo, it prevents syntax errors that could cause you to get locked out. Just be careful with long lines in nano so they don't get wrapped.

  8. #8
    Join Date
    Apr 2006
    Location
    Ubuntuland
    Beans
    2,124
    Distro
    Ubuntu 13.10 Saucy Salamander

    Exclamation Re: visudo

    Quote Originally Posted by Lars Noodén View Post
    That's what that line does. When an environment variable precedes a program name, that variable is local to that program session. So in the example above EDITOR is set to nano just that once only for that particular session with visudo.

    Anyway, +1 to using visudo, it prevents syntax errors that could cause you to get locked out. Just be careful with long lines in nano so they don't get wrapped.
    The EDITOR variable is used by many, many programs and they will all run: "nano visudo" + their arguments (usually another file name to edit) instead of just "nano" + their own arguments. You do NOT want visudo in the EDITOR variable.

    Maybe you're thinking of:
    Code:
    EDITOR=nano; visudo
    Last edited by Slim Odds; December 6th, 2013 at 04:37 AM.
    24 beers in a case, 24 hours in a day. Coincidence? I think not!

    Trusty Tahr 64 bit, AMD Phenom II 955 Quad Core 3.2GHz, GeForce 9600 GT
    16G PC2-6400 RAM, 128 GB SSD, Twin 1TB SATA 7200 RPM RAID0

  9. #9
    Join Date
    Sep 2006
    Beans
    8,627
    Distro
    Ubuntu 14.04 Trusty Tahr

    Setting environment variables temporarily

    Quote Originally Posted by Slim Odds View Post
    You do NOT want visudo in the EDITOR variable.
    Of course not, that's why EDITOR is prepended to the line launching visudo, not on a separate line or separated by a semicolon, so that EDITOR remains unchanged, except for that single instance of visudo. I'm not finding a good web page explaining that, but it's widely used when compiling. Try this:

    Code:
    EE=foo
    echo ${EE}
    EE=bar less ~/.profile
    echo ${EE}
    less ~/.profile
    echo ${EE}
    While in less both times check EE by entering !echo ${EE}. You'll see that in the first instance, it is set to "bar" and for everything else, it remains "foo"

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
  •