16

My Ubuntu 14.04 is asking for my password to mount or unmount an USB stick. How can I change it, so that the mount is automatic and no password input is required ?

This is about mounting arbitrary USB sticks in /media, there is no entry in /etc/fstab. My user is in the 'plugdev' group, but the password prompt is pupping up anyway.

markus_b
  • 261

5 Answers5

14

Try this. Just press Ctrl+Alt+T on your keyboard to open Terminal. When it opens, run the command(s) below:

sudo gedit /usr/share/polkit-1/actions/org.freedesktop.udisks2.policy

When it opens look for

<action id="org.freedesktop.udisks2.filesystem-unmount-others">
<defaults>
      <allow_any>auth_admin</allow_any>
      <allow_inactive>auth_admin</allow_inactive>
      <allow_active>auth_admin_keep</allow_active>
</defaults>

And change it to

<action id="org.freedesktop.udisks2.filesystem-unmount-others">
<defaults>
      <allow_any>yes</allow_any>
      <allow_inactive>yes</allow_inactive>
      <allow_active>yes</allow_active>
</defaults>
Serge Stroobandt
  • 5,719
  • 1
  • 54
  • 59
Mitch
  • 109,787
4

It is not a good solution, to alter .policy files in /usr/share/polkit-1/actions directory, as other answers suggest, since the files may be overwritten on software update. A permanent solution is to create a .pkla file in a sub-directory of /etc/polkit-1/localauthority directory, as man pklocalauthority suggests. While .policy files declare actions and default PolicyKit behavior for them, .pkla files adjust that behavior.

Start editing a new .pkla file:

sudo nano /etc/polkit-1/localauthority/50-local.d/50-easy-mount.pkla

If you only care for local sessions (using local monitor and keyboard), write this:

[Allow local mounting without password]
Identity=unix-group:sudo;unix-group:plugdev
Action=org.freedesktop.udisks2.filesystem-mount
ResultActive=yes

In Debian (and Ubuntu is Debian-based), members of plugdev user group are allowed to mount removable devices and members of sudo are allowed anything. So, you only allow password-less mounting to those who have the rights to mount anyway. (In Ubuntu 20.04 and probably in many other systems, you don't rather need to allow this, as it is already allowed in /usr/share/polkit-1/actions/org.freedesktop.UDisks2.policy).

If you wish to also allow mounting in ssh sessions, write this:

[Allow mounting without password]
Identity=unix-group:sudo
Action=org.freedesktop.udisks2.filesystem-mount;org.freedesktop.udisks2.filesystem-mount-other-seat
ResultAny=yes

Here, password-less mounting is granted to admins only (sudo user group), because org.freedesktop.udisks2.filesystem-mount-other-seat action is triggered on mounting attempt by a user who is logged in via ssh and is not logged in locally at the same time. So, mounting with this action potentially allows access to a USB flash drive of another person who is working locally. Change the Identity key to whatever suits your security considerations. For example, to grant password-less mounting to admins and users john and mary, you write:

Identity=unix-group:sudo;unix-user:john;unix-user:mary

Mount like this:

udisksctl mount --options noatime --block-device /dev/sdb1

Unmounting own mounts doesn't ask for password:

udisksctl unmount --block-device /dev/sdb1

See man pklocalauthority, man polkit and man udisksctl for more details. Tested on Ubuntu 20.04.

1

I had the same problem today; "all of a sudden" my 14.04 wanted my password for "everything"; including (un)mount of USB sticks.

I figured that I installed openssh-server in the morning. After removing it, everything is back to normal; I can insert a USB stick; and it is mounted without asking for a password. Strange. Just tried to repro; installed openssh-server again; and no ... no such effect this time.

GhostCat
  • 2,165
1

I had the same problem with mounting on one of my systems. I tried using @Mitch approach above which didn't work for me (Although it may work great if you have the unmounting issue) . I took a similar approach to begin with and

sudo gedit /usr/share/polkit-1/actions/org.freedesktop.udisks2.policy

but changed this section

<defaults>
      <allow_any>auth_admin</allow_any>
      <allow_inactive>auth_admin</allow_inactive>
      <allow_active>yes</allow_active>
    </defaults>

of

<action id="org.freedesktop.udisks2.filesystem-mount">

to

 <defaults>
      <allow_any>no</allow_any>
      <allow_inactive>no</allow_inactive>
      <allow_active>yes</allow_active>
    </defaults>

matching content found in the old

/usr/share/polkit-1/actions/org.freedesktop.udisks.policy

Sources: @Mitch answer above

     `/usr/share/polkit-1/actions/org.freedesktop.udisks.policy`

     https://forum.kde.org/viewtopic.php?f=22&t=112092

Testing

Elder Geek
  • 36,752
0

I also faced this problem two times. Asking for password not only during mount-umnount usb but also during other task like launching any application. I solved it by restarting system. It always worked for me.

d a i s y
  • 5,551