3

In the terminal I have to use sudo mount, otherwise it says operation not permitted.

But in the file explorer (started normally, without sudo) I can mount by pressing the icon next to the external disk (or right click -> Mount) and it works. How do I use the same technique in bash to mount a usb drive without sudo?

1 Answer 1

7

The file managers uses UDisks2 to mount the external drives without admin rights. GNOME, KDE, XFCE and various other desktop environments uses UDisks2 to allow normal users to mount removable media devices.

UDisks2 project provides a system daemon called udisksd, and a command-line tool called udisksctl.

The udiskd daemon runs in the background and implements well-defined D-Bus interfaces that can be used to query and manipulate storage devices. udiskd starts automatically at system boot and runs as root all the time. You can verify it using command:

sudo systemctl status udisks2

Below are the steps to mount a usb disk without sudo!

1. Find what the drive is called
You'll need to know what the drive is called to mount it. To do that enter the command below

lsblk

You're looking for a partition that should look something like: /dev/sda1 or /dev/sdb1. The more disks you have the higher the letter this is likely to be. Anyway, find it and remember what it's called.

2. Mount using udisksctl

udisksctl mount -b /dev/sda1

Sample Output:

Mounted /dev/sda1 at /media/myusername/usb_stick_name.

3. Unmount the disk

Similarly, you can unmount the USB drive using command:

udisksctl unmount -b /dev/sda1
1
  • 1
    This is still requesting me the password when executing udisksctl mount -b /dev/sda1 and after this it is not possible to create files in the mounted unit without sudo access...
    – user171780
    Commented Mar 3, 2023 at 6:47

You must log in to answer this question.

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