5

I know I can give permission to use "mount/unmount" through sudo some users without password.

But how can I give permission to use "mount/unmount" only for /dev/sda2 and not for /dev/sda10?

For example, some user can execute: sudo mount -t ntfs /dev/sda2 ~/mnt/ntfs
But the same user must not have permission to execute: sudo mount /dev/sda10 ~/mnt/s10

Braiam
  • 67,791
  • 32
  • 179
  • 269
Dimetry
  • 247
  • 1
  • 3
  • 13

2 Answers2

10

you could create a simple file:

 sudo visudo -f /etc/sudoers.d/myOverrides 

with this directive:

 User ALL = NOPASSWD:/sbin/mount -t ntfs /dev/sda2 /home/User/mnt/ntfs

This allow User to runs mount command with those parameter without entering a password.

Here is sudo manual for more details.

Lety
  • 6,039
  • 2
  • 29
  • 37
  • Still problem.
    sudo -l: User dmit may run the following commands on mintPC: (ALL : ALL) ALL (root) NOPASSWD: /bin/mount -t ntfs /dev/sda2 /home/dmit/mnt/ntfs /bin/mount -t ntfs /dev/sda2 /home/dmit/mnt/ntfs mount: only root can do that
    – Dimetry Oct 07 '14 at 12:28
  • You should run mount with sudo: "sudo mount -t ntfs /dev/sda2 /home/dmit/mnt/ntfs" and this will not ask you for password – Lety Oct 07 '14 at 15:50
  • You are right. Solved. ty – Dimetry Oct 07 '14 at 15:59
0

You can specify arguments in the sudoers file, something like this should work:

user ALL=(ALL) /sbin/mount -t ntfs /dev/sda2 /home/user/mnt/ntfs, /sbin/umount /dev/sda2
fkraiem
  • 12,555
  • 4
  • 35
  • 40