Allow users of a certain group to run a command without sudo

11

6

I know how to edit /etc/sudoers so that I can run a command as sudo without having to enter my password, however is there a way of allowing a program to be run completely without sudo, by all users of a group. (The programs I want to run is "mount" and "umount").

w4etwetewtwet

Posted 2013-08-26T10:32:53.170

Reputation: 272

What is your OS? Are you trying to mount a NTFS partition, EXT partition, or optical drive? – nate – 2013-08-26T13:35:02.470

Answers

13

Suppose I wanted to add a group of users who are allowed to run mount and umount without passwords. So I first want to add a group called "anyname"

sudo groupadd anyname

Next we need to edit the /etc/group and add the users

anyname:x:407:

will be present ,hence append users you want to add the users seperated by commas.

anyname:x:407:user1,user2,...

Now we need to configure sudo to allow members of the "anyname" group to actually invoke the mount and umount commands.

You just need to add the following lines to /etc/sudoers

%anyname ALL=NOPASSWD: /sbin/mount, /sbin/umount

Now sudo mount wont ask password but since it is a pain in the butt typing sudo all the time, we can avoid it by dong the following:

I can create the following script called "/usr/bin/mount" (and similar script for umount)

#! /bin/sh
sudo /sbin/mount $*

To make this slightly more secure, We might want to change the ownership of these scripts to the "anyname" group.

chgrp anyname /usr/bin/mount /usr/bin/umount

and then make them executable only for the group "anyname"

chmod g+x /usr/bin/mount  /usr/bin/umount

EDIT:Depending on the OS you are using please check where mount and umount commands are located. It might be in /bin/ instead of /sbin.So you might have to make necessary changes

IMPORTANT: BTW don't run the script on Arch based systems where all of the bin folders are symlinked with each other.

Stormvirux

Posted 2013-08-26T10:32:53.170

Reputation: 877

1Thanks. I actually have implemented using a global .bashrc, that contains a function mount that looks like this: mount { sudo mount $* } – w4etwetewtwet – 2013-08-26T15:52:17.793