LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   sudo passwordless commands (https://www.linuxquestions.org/questions/linux-newbie-8/sudo-passwordless-commands-883246/)

segmentation_fault 05-28-2011 05:02 PM

sudo passwordless commands
 
What I'm trying to do is to grant my regular user to locally mount partitions and shutdown the machine without a password. Here is what I've done to /etc/sudoers:
Code:

Host_Alias LOCAL = localhost

Cmnd_Alias SHUTDOWN = /sbin/shutdown
Cmnd_Alias MOUNT = /bin/mount, /bin/umount

<my_username> LOCAL=(root) NOPASSWD: SHUTDOWN, MOUNT

%wheel ALL=(ALL) ALL

My user is a member of wheel group and I want to type the password for each sudo command except for shutdown and mount.
However I am asked for a password whenever I execute "sudo mount [...]" or "sudo shutdown [...]".
Am I missing something?

T3RM1NVT0R 05-28-2011 06:43 PM

@ Reply
 
Hi there,

Try adding this to your sudoers file:

<my_username> LOCAL=(root) NOPASSWD: /sbin/shutdown
<my_username> LOCAL=(root) NOPASSWD: /sbin/mount

jschiwal 05-28-2011 06:56 PM

Does gentoo use PolicyKit. You can add a policy allowing GUI users to have removable media mounted.
Look at "polkit-auth". If it lists policies, is "org.freedesktop.hal.storage.mount-removable" listed?

segmentation_fault 05-28-2011 08:42 PM

Well, there are some entries under /etc/polkit-1/ and /var/lib/polkit-1/ so I suppose it does. However this should only resolve the mount issue, not the shutdown.
And I'm not actually a GUI user. The default login is in terminal from which I invoke blackbox WM (through startx). I don't have either KDE or Gnome or any other WM/DE installed. That's why I'm trying to make these two commands work without password (just to avoid typing it so frequently). And of course to understand further how sudo works.
Is it possible that wheel group rule "overwrites" somehow the NOPASSWD rule for the user?

segmentation_fault 05-28-2011 09:07 PM

Looks like it is solved. First of all, instead of "localhost", I put the hostname of the machine.
Secondly, I put the user rule after the group rule
Code:

%wheel ALL=(ALL) ALL
<my_username> <hostname> = (root) NOPASSWD: MOUNT, SHUTDOWN

and it seems that did the trick. Now I can mount/unmount and shutdown without a password and for any other sudo operation I am asked for a password.
Thanks for the replies.


All times are GMT -5. The time now is 05:16 AM.