Solution 1:

Nautilus and other file managers that mount drives (i.e., the GUI) use the udisks command.

This provides a dynamic mount, where the mount point is created for the drive on-the-fly, and when the drive is unmounted, the mount point goes away.

See man 1 udisks for details on how to use this command (either manually, or called from a script/application). To learn more about how udisks works, see man 7 udisks.

To mount a device with udisks, you must specify a valid device name for the device. Specifying the device's volume name will not work. So, you can use udisks like this:

udisks --mount /dev/sdb1

When manually using udisks from the command-line, you might be best off to simply plug in a device, then run dmesg | tail shortly thereafter (see man dmesg and man tail) to discover the device name of the newly attached device.

This may not be the best way to write a script that mounts devices with udisks, however. I don't know exactly how you should do it, and it would be difficult to know since you haven't told us precisely what you want this script to do and when you want it to mount devices.

Solution 2:

Since I do not want to automount on boot, fstab is out of the question (right?).

Nope. noauto keyword makes it skip mounting at boot time.

Is there an "easy" way to mount via CLI, just like it does on the GUI by clicking on an unmounted drive?

Easiest would be to add it to /etc/fstab with noauto and use ...

mount /dir

This will have mount probe for a mountpoint and if not found then for a device in /etc/fstab. /dir needs to exist though.

If either device or UUID are provided /etc/fstab is not probed. Like so ...

mount /dev/sda1 /media/directory

Or use udisks (I will let Eliah handle that >:-) )


mount generally is super user only.

Example options:

  • rw,noauto,user mounts it as read+write but not at boot and you can do it as a user.

  • You can also add in permissions for a user in /etc/fstab for files. You can use umask for that.

  • umask=0444 : everyone read, no write, no execute.

  • umask=0333 : everyone read, execute.

  • umask=0338 : owner, group read and execute; others, nothing

Solution 3:

In one of the comments, you said:

For whatever reason, I'm getting "Mount failed: Not Aouthorized" when running it via ssh

I use pmount instead of udisks. It works over ssh.

If I remember correctly, this is the syntax/etc I use with it - most of mine are hidden behind aliases at this point:

pmount /dev/sdb1 my_usb
ls /media/my_usb/
eject /media/my_usb