2

I want to mount/umount a 3rd hard disk (with a NTFS filesystem) under Linux (OpenSuse (Leap15.2)) only as needed and as a normal user. But without entering my root password every time. So far I have tried it with entries in the fstab and in sudoers, but each time I must type the root password. Below are the entries in fstab and sudoers:

in sudoers:

root    ALL = (ALL) ALL
ALL     ALL = (ALL) ALL
#
%users  ALL = (root) NOPASSWD:/usr/bin/mount
%users  ALL = (root) NOPASSWD:/usr/bin/umount

in fstab:

LABEL=DATA3 /home/leap153/data3  ntfs-3g noauto,uid=1000,gid=100,dmask=002,fmask=002,noatime  0 0

FUSE is installed and uid and gid have the correct number of the user (checked).

3
  • What command you try to execute with sudo? Commented May 28, 2022 at 11:45
  • I'm unfamiliar with NTFS-mounts, but are you able to add any other commands using NOPASSWD to sudoers and run them passwordless? Did you edit the file with visudo if that's applicable on OpenSuse?
    – sampi
    Commented May 28, 2022 at 11:47
  • Maybe also check out Systemd automounting. It is flexible and just works – if you use systemd anyway.
    – Daniel B
    Commented May 28, 2022 at 12:35

1 Answer 1

1

Don't do it by configuring sudo to allow mount, this is highly insecure. See https://security.stackexchange.com/questions/258637/why-do-i-need-the-root-password-when-mounting-an-internal-drive-in-linux for details.

Instead, try adding the user option in fstab and then use mount without sudo. Note that this only works with kernel 5.15 and later and the new ntfs3 driver:

 LABEL=DATA3 /home/leap153/data3  ntfs3 noauto,user,uid=1000,gid=100,dmask=002,fmask=002,noatime  0 0

Then

 mount /home/leap153/data3

Another alternative is to use autofs or possibly udisks.

Unfortuantely, udisks doesn't work with volume labels, so you will need to determine the real block device for the partition. You can use the blkid -L data3 command to find it. For example

udisksctl mount -b /dev/sdb1

which likely will mount your partition (it will tell you where) as /media/user/DATA3 (where user is your username). Note that this will only work without sudo for the user logged into the console.

The third alternative using autofs is more automatic but also more complicated to set up, but will work for all users, both local and remote.

8
  • @RomeoNinov: in terminal I do this sudo mount /home/leap153/data3 and it works with entered password @sampi: 1) yes, visudo is present in Suse, but I edited sudoers directly as root with vi. Does that make a difference? 2)Yes, I tried VERACRYPT in sudoers because it also constantly asks for the root password (and removed again because it did not work).
    – Genschman
    Commented May 28, 2022 at 13:02
  • despite user entry and reboot the problem remains unchanged. However, I get the following message: Unprivileged user can not mount NTFS block devices using the external FUSE library. Either mount the volume as root, or rebuild NTFS-3G with integrated FUSE support and make it setuid root. Please see more information at tuxera.com/community/ntfs-3g-faq/#unprivileged
    – Genschman
    Commented May 28, 2022 at 13:11
  • What kernel version are you using? Might be able to use something other than ntfs-3g. Otherwise autofs or udisks is a better bet.
    – user10489
    Commented May 28, 2022 at 13:13
  • Updated answer with more details why this didn't work and alternatives.
    – user10489
    Commented May 28, 2022 at 22:53
  • blkid can be used to "resolve" label / uuid btw
    – Tom Yan
    Commented May 29, 2022 at 2:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .