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

9
  • the sudo command let you become root for a while. So, if you are root, shall be no limitations
    – feligiotti
    Oct 7, 2014 at 8:10
  • @gio900 The point is that one wants to only allow a given user to run a specific command with a specific parameter with root privileges.
    – fkraiem
    Oct 7, 2014 at 8:12
  • so I cant restrict mount only for /dev/sda2?
    – Dimetry
    Oct 7, 2014 at 8:12
  • ok, so if you let that user to run a script instead the command, thats limitation will be in the script
    – feligiotti
    Oct 7, 2014 at 8:14
  • @gio900 how can I make such script?
    – Dimetry
    Oct 7, 2014 at 8:16

2 Answers 2

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.

3
  • 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 7, 2014 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 7, 2014 at 15:50
  • You are right. Solved. ty
    – Dimetry
    Oct 7, 2014 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

You must log in to answer this question.

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