I have been through this kind of feature in older versions of Ubuntu. When I'd like to mount a partition it will ask me a password. Now I want to enable that kind of feature in Ubuntu 12.04.
How can I achieve this?
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.
Sign up to join this communityAccording to the Ubuntu ManPage Repository, pklocalauthority - PolicyKit Local Authority makes a distinction between user authentication (to make the user in front of the system prove he really is the user) and administrator authentication (to make the user in front of the system prove he really is an administrator)
Therefore you can use this policykit to provide administration authentication for mounting all (internal and external) devices.
To do so, follow these steps:
Open a terminal(CTRL+ALT+T) and type:
gksu gedit /var/lib/polkit-1/localauthority/10-vendor.d/com.ubuntu.desktop.pkla
In line 4, look for ResultActive=yes
and change it to:
ResultActive=auth_admin_keep
Save and Close the file.
Ubuntu will now require a password when mounting all drives (internal and external drives).
For specific partitions:
In 10.04 and newer versions, mounting all devices (internal and external) are allowed without asking for password unless it was defined in the filesystem table (fstab
) file.
Therefore, to make Ubuntu prompt users for sudo
password when mounting specific partitions, you need to edit your fstab
file.
To do so, follow these steps:
Open a terminal and type:
gksu gedit /etc/fstab
At the last line, add the UUID of your partition with the defaults option.
You can find out the UUIDs of partitions by running blkid
in the terminal.
For example:
$ sudo blkid
/dev/sda1: UUID="5474ce02-5c07-4002-a0e7-10c8bc5dba2c" TYPE="ext4"
/dev/sda2: LABEL="windows" UUID="7355DDFB0563F31F" TYPE="ntfs"
/dev/sda5: LABEL="data" UUID="7e3fbc57-03fe-4742-bb72-756f31852059" TYPE="ext4"
/dev/sda6: LABEL="films" UUID="a319fb28-3061-404f-abbc-6519cf81c6c9" TYPE="ext4"
/dev/sda7: LABEL="tv" UUID="5D10E5D66886BCCF" TYPE="ntfs"
/dev/sda8: UUID="12d16683-5530-454e-809b-1a30ed47a8c9" TYPE="swap"
Now that you know the UUID, you can add it to the fstab
file. But first, you need to create a mountpoint where the partition will be mounted.
You can do that by running:
sudo mkdir /path/to/dir/name-dir
In my example, I want to mount the partition under /media/data:
sudo mkdir /media/data
Now, I can simply add the line below to make sure that Ubuntu prompts for a password when the "data" partition is mounted:
UUID=7e3fbc57-03fe-4742-bb72-756f31852059 /media/data ext4 defaults 0 0
Save and Close the file.
Note:
The defaults option uses the default options that are rw, suid, dev, exec, auto, nouser, and async.
The user allows normal users to mount the device, whereas nouser lets only the root to mount the device.
For detailed information, visit How to edit and understand /etc/fstab.
fstab
) file and add that specific partition with defaults
option which implicitly implements the nouser
option which lets only the root to mount the device. Will edit my answer to add this info.
/etc/fstab
is for...
The easy answer is to edit the policy file with one of the commands below:
gksu gedit /var/lib/polkit-1/localauthority/10-vendor.d/com.ubuntu.desktop.pkla
or
sudo -H gedit /var/lib/polkit-1/localauthority/10-vendor.d/com.ubuntu.desktop.pkla
And add #
at the start of line 2
Identity=unix-group:admin;unix-group:sudo
changing it to
#Identity=unix-group:admin;unix-group:sudo
Since the system will no longer identify mount requests as admin or sudo requests it will require the password for mount requests not listed as user mountable in /etc/fstab
.
To ask password when you also mount USB drives (above answer by @Peachy works only for internal drives),
Open Terminal (Shortcut = Ctrl+Alt+T).
Type
sudo gedit /var/lib/polkit-1/localauthority/10-vendor.d/com.ubuntu.desktop.pkla
Add org.freedesktop.udisks2.filesystem-*;
to Line 3.
Change line 4, ResultActive=yes
to ResultActive=auth_admin
.
After edits Lines 1 -4 will look like :
[Mounting, checking, etc. of internal drives]
Identity=unix-group:admin;unix-group:sudo
Action=org.freedesktop.udisks.filesystem-*;org.freedesktop.udisks.drive-ata-smart*;org.freedesktop.udisks2.filesystem-mount-system;org.freedesktop.udisks2.encrypted-unlock-system;org.freedesktop.udisks2.filesystem-fstab;org.freedesktop.udisks2.filesystem-*;
ResultActive=auth_admin
Save and Close file.
Now Ubuntu will ask password each time before mounting usb-drives.
This worked for me in Ubuntu 20.04.