Allow user to perform one root comand without password request

Hi,

Opensuse 13.2, fully updated, KDE 4

I sometimes have to mount a distant network drive.
This I do with

 mount -t cifs "//<network address>/partition" /mnt/mountpoint -o guest,rw,iocharset=utf8,file_mode=0777,dir_mode=0777 

I do that by becoming root (with su -) and then typing in that command, and giving the root password.

For several reasons without importance here, it is not practical to include the equivalent line
in /etc/fstab to have this automounted at startup.

I would like normal users to be able to perform this command as well, without the need to type in
the root password, nor their own password.

Is that possible?

I naively included the following line in the /etc/sudoers file, hoping that this would allow that:

 username ALL= NOPASSWD: /sbin/mount, /usr/sbin/mount.fuse, /bin/mount, /sbin/mount.ntfs (and all other /sbin/mount.xxx)

(I’m aware that this would give user “username” the power to use the mount command for all mount operations
and not only the one described above).

But I still get

 mount: only root can use "--options" option

as a result.

Any help would be appreciated.

Thanks in advance

Lenwolf

I do of course not know your “several reasons”. But when you add the option noauto to the /etc/fstab entry, the system will not try to mount it at boot. So when your only reason is that it should not be mounted at boot (what you call “automounted”). that reason is nil.

This will considarably shorten what you have to type when you want to mount it. E.g.:

mount /mnt/mountpoint

will be sufficient.

Hi Henk, Thank you very much for that piece of advice. However, that doesn’t solve my problem, or does it? Would a normal user be able to issue the mount command without being prompted for any password? Thanks. Lenwolf

You’re running the command without sudo, that’s the problem.

Sudoers file does not magically allow commands to be run arbitrarily, you need to run it with sudo your_cool_commands

Hi,
this is one of those instances where you sit in front of your computer, read the answer you just got and hit your head on the table asking how could I not see that?
Well, I couldn’t…
Thanks, your reply does the trick!

Lenwolf

Well, first step is to minimize the command and then of course sudo, properly configured, is able to let users use commands running “as root” with the root password, the user’s password or no password.

Yes, thank you!

Lenwolf

Try adding the “user” mount option, then a plain user should be able to mount it without gaining root privileges.

I don’t know whether that works with Samba shares though, it doesn’t with NTFS-3g e.g.

On 2015-04-22 13:06, lenwolf wrote:
>
> Hi Henk, Thank you very much for that piece of advice. However, that
> doesn’t solve my problem, or does it? Would a normal user be able to
> issue the mount command without being prompted for any password?

Yes, you can mount something that is listed in fstab if it includes the
option “user”, as plain user without giving any password or having to
use sudo.


Cheers / Saludos,

Carlos E. R.

(from 13.1 x86_64 “Bottle” (Minas Tirith))