I would like users to be able to mount ext3 image files as a loop back devices in read only and no execution modes without having to invoke sudo. The sudo command currently used is something like:
$ EXT3_DIR=$(mktemp -d /tmp/ext3-mnt-XXX) ; sudo mount -o loop,ro,user rootfs.ext3 ${EXT3_DIR} && cd ${EXT3_DIR}
With that (and visudo), I created a file: /etc/sudoers.d/ext3-ro-mount with the contents:
user ALL=(root) NOPASSWD: /bin/mount -o loop\,ro\,user *.ext3 /tmp/ext-mnt-*
But when I run the mount command without sudo elevation, I get the error:
mount: only root can use "--options" option
How can I achieve this for users? (and what would the subsequent /etc/sudoers.d/ext3-ro-umount conent look like?)
EDIT:
Having misunderstood how what I was doing is actually meant to work, I ran the command with sudo on a less privileged account, entered the password and got this error:
{such and such} is not in the sudoers file. This incident will be reported.
How do I add a user to the sudoers file without making them a full blown sudoer? Is this achieved by creating a new group and give the group permission to do this?
EDIT 2:
I figured out the issue I was having. See my answer below.
rootfs.ext3, but in reality, only the suffix (.ext3) will be fixed. – Jamie Oct 13 '20 at 16:36sudoin front of the mount command? – meuh Oct 13 '20 at 16:52sudoto the command isn't the issue: I don't want them to havesudoprivileges, just the ability to mount/umount an image with the restrictions I outlined. – Jamie Oct 13 '20 at 17:28sudoand you already have a default entry for%sudo ALL=(ALL:ALL) ALL, as some distributions do (or%wheelfor Fedora). You don't have to do that. – meuh Oct 13 '20 at 17:57sudo. It is the other way round: it allows the user to run that command line (and only that one) usingsudo, whilesudo any other commandwill fail. – fra-san Oct 13 '20 at 21:29-o loop\,ro\,noexecin the file. A command must contain-o loop,ro,noexecto match this. Your command contains-o loop,noexec,ro.sudoneither is aware nor cares if these are equivalent formount, it compares character strings. – Kamil Maciorowski Oct 13 '20 at 23:01