Sudoers problem

I am having issues with sudoers file.

I want to add the commands shutdown, reboot, mount, and umount to not require a password.

myuser ALL=(ALL) NOPASSWD: /sbin/shutdown
myuser ALL=(ALL) NOPASSWD: /sbin/reboot

The above two work fine, but mount and umount do not. I presume because there is not a single “mount” file in /sbin, but mount.cifs, mount.nfs etc. etc.

How can I make this work?

sudo does support the use of wildcards, see the Wildcards section of man sudo for details.

As you again (intentionally?) do not show what you did, this can only become presuming contest.

Show the actual configuration that does not work, show what happens when you are using sudo with this configuration.

You do not use filesystem-specific commands directly so I fail to see how it is relevant.

You can specify something like /usr/sbin/mount.* as the command, as I understand it. Though I really don’t see why just putting /usr/bin/mount in as the command wouldn’t work - as you point out, the sudoers lines that aren’t working are not present in OP’s post, so we don’t really know what he’s trying to do.

ETA: I see now that that’s not how it works; wildcards are allowed for parameters to the command, but not the command itself. My mistake.

user ALL=(ALL) NOPASSWD: /sbin/mount
user ALL=(ALL) NOPASSWD: /sbin/umount

And what is the output you receive when you try to run those commands with sudo?

The output in combination with the configuration is going to be the most helpful. “It doesn’t work” doesn’t really tell us much.

Could you provide what the use cases are for all that you want to do?

bor@leap15:~> ls -l /sbin/mount
ls: cannot access '/sbin/mount': No such file or directory
bor@leap15:~> grep PRETTY_NAME /etc/os-release
PRETTY_NAME="openSUSE Leap 15.6"
bor@leap15:~> 

The command /sbin/mount does not exist and any line in /etc/sudoers that refers to it is ignored when you try to run sudo mount because sudo attempts to execute command located somewhere else.

And according to the first post, you are aware that /sbin/mount does not exist. Then what did you expect from this /etc/sudoers line and why?

1 Like

By “it doesn’t work” I mean I am still prompted for the password.

My goal is to be able to mount and unmount volumes without having to enter the root password (the same as the entries for shutdown and reboot).

Try using /usr/bin/mount instead of /sbin/mount - as @arvidjaar notes, /sbin is the wrong path.

1 Like

BTW, if the devices/paths you want to mount are defined in /etc/fstab, you can add the user option to the line in fstab, and you won’t need to use sudo.

Since you haven’t specified if you want specific filesystems or just to allow the user to arbitrarily mount anything anywhere, I figured I’d let you know about that option as well.

1 Like

Those two solutions work great. Thank you.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.