I recently needed to be able to mount volumes on a Linux server from a script and I ran into the "mount: only root can do that" error, even with an intermediate SUID script (because I believe mount checks the real user id, not just the effective one). The device and mount point are not consistent so adding an entry to /etc/fstab wasn't an option, nor was passing a password to sudo.
Enter the /etc/sudoers file. By default sudo requires that a user provide their password, but you can use the NOPASSWD option to bypass this requirement. This was perfect.
To allow the user corey to run /bin/mount and /bin/umount on all machines without a password add the following line to /etc/sudoers:
corey ALL=NOPASSWD: /bin/mount, /bin/umount
To allow all members of the group 'wheel' to run /bin/mount and /bin/umount on all machines without a password add the following line to /etc/sudoers:
%wheel ALL=NOPASSWD: /bin/mount, /bin/umount
Now one of the privileged users can run:
sudo mount /dev/sdb1 /some/path/to/mountpoint
And mount without issue – or a password prompt.


