I recently moved from Ubuntu 14.10 to Debian Testing. Under Ubuntu I had a shell script for backing up my home folder to a USB stick. The last line of the script unmounts the USB stick. Adapting it to Debian's file system, it should be:

umount /media/usb0

(or umount /media/usb which links to /media/usb0). But when I execute the script, this last line throws umount: /media/usb0: umount failed: Operation not permitted. Obviously, with sudo it works, but I'm wondering why I need to be sudo here (was not necessary on Ubuntu). Any ideas how to circumvent that, so how to unmount the USB stick without being root? (the remaining part of the script runs flawlessly).


This is my /etc/fstab:

# <file system> <mount point>   <type>  <options>       <dump>  <pass>
/dev/mapper/sklar--vg-root /               ext4    errors=remount-ro 0       1
# /boot was on /dev/sda1 during installation
UUID=a90bee04-e08a-4a86-8465-762aca5719a4 /boot           ext2    defaults        0       2
/dev/mapper/sklar--vg-swap_1 none            swap    sw              0       0
/dev/sdb1       /media/usb0     auto    rw,user,noauto  0       0
  • Please paste the relevant line in your /etc/fstab. You probably just need to change a parameter there to allow user unmounting. – Faheem Mitha Apr 3 '15 at 13:05
  • Your /dev/sdb1 has user option in /etc/fstab/, meaning that can be mounted by users and umounted by the same user that mount-ed it. You should replace user with user=youruser to always be able to umount it as youruser. Also, if your USB device is always the same, i recommend replacing /dev/sdb1 with UUID="uuidof/dev/sdb1". – petry Apr 3 '15 at 13:28

By default, mount is only allowed for root, or, if specified in /etc/fstab, by users.

Now, if you USB drive is auto-mounted without being specified in /etc/fstab (or manually by root), will not be mounted with user=youruser option, so youruser will be unable to umount it.

If your USB drive is specified in /etc/fstab with user option, any user will be able to mount it, and the same user (and root) will be able to umount it.

What you need, is for your USB drive to be specified in /etc/fstab, with user=youruser. In that case, no matter if root or youruser mounts the USB drive, youruser will be able to umount it.

| improve this answer | |

Here are typical lines in /etc/fstab for an external USB mass storage device.

UUID="4E1AEA7B1AEA6007" /mnt/passport  auto    rw,user,noauto  0       0

This particular one happens to be for my Passport USB hard drive. Notice the user keyword in the fourth field. This field (the mount options associated with the filesystem) tells the system to allow users to mount and unmount the device. There are other options, but the use of user is quite common and typical. The UUID is obtained from blkid, and is an identifier for the storage device.

For more details, see man mount, specifically the section "The non-superuser mounts." This says:

The non-superuser mounts.

Normally, only the superuser can mount filesystems. However, when fstab contains the user option on a line, anybody can mount the corresponding system.

Thus, given a line

 /dev/cdrom  /cd  iso9660  ro,user,noauto,unhide

any user can mount the iso9660 filesystem found on his CDROM using the command

 mount /dev/cdrom


 mount /cd

For more details, see fstab(5). Only the user that mounted a filesystem can unmount it again. If any user should be able to unmount, then use users instead of user in the fstab line. The owner option is similar to the user option, with the restriction that the user must be the owner of the special file. This may be useful e.g. for /dev/fd if a login script makes the console user owner of this device. The group option is similar, with the restriction that the user must be member of the group of the special file.

| improve this answer | |
  • Hi Faheem, thanks for helping. Can you be more specific which line I should put in /etc/fstab then? (up to it's UUID) – Marius Hofert Apr 3 '15 at 13:20
  • @MariusHofert there should be a line in /ec/fstab for it already. Isn't there? – Faheem Mitha Apr 3 '15 at 13:21
  • ah... see the update. But I have auto etc. in there... what do I have to change? – Marius Hofert Apr 3 '15 at 13:25
  • @MariusHofert that auto is for the filesystem. Your options are already good as is, you don't need to change anything. You should already be able to unmount as user, but it should be the same user. What user is your shell script running as? Try manuall mounting and then immediately unmounting as your user account. Does it work or not? If not, give the error. – Faheem Mitha Apr 3 '15 at 13:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.