When I insert a thumb drive, media card, or USB hard drive, to unmount it via the command line, I need to use:
sudo umount /media/the_device
But, I can unmount the device in a file manager like Nautilus simply by clicking the eject button or using the right-click context menu on the device.
What is the rationale for the difference? How can I change it so that I can unmount from the command line without needing root privileges? Is changing it a bad idea?
Edit: In case it has changed, I am running 9.04. I've run most versions 5.10--9.04, and as far as I recall, it has always been this way.
Nautilus doesn't unmount the device directly; it talks over DBus to a system daemon (udisks-daemon) and asks it to unmount.
The daemon checks if you're allowed to do that, by contacting another system daemon, PolicyKit.
PolicyKit uses the configuration defined in
/usr/share/polkit-1/actions/org.freedesktop.udisks.policy
(unless the local system administrator overrides it in/etc/polkit-1
). That file tells PolicyKit that users with active console sessions can detatch drives, so PolicyKit talks to a third daemon, ConsoleKit, to see if you have active console sessions. Logging in via gdm counts as a console session; logging in via ssh doesn't.There's a command-line tool
udisks
that lets you unmount devices without using sudo, using the same mechanism:that unmounts the filesystem; I can also detatch the whole device with
which makes the LED on my USB key go dark.
The situation might have changed -- in current Ubuntu 10.04 umount works without sudo for USB drives. Generally I think that the command
(gvfs-mount is in the gvfs-bin package) should always work.
Current answers are deprecated. Try with GIO command line tool.
Get the current mounted partitions with, for example:
Reference