Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm currently trying to write a couple of systemd/udev configuration files that will allow me to automount/unmount MTP Android devices on my Arch Linux laptop. It took me some time, but so far it works pretty well.

Now, I would like for any user with fuse permissions to be able to unmount the device. So far, it's only possible for the same user as the one go-mtpfs was started as.

I'm well aware that MTP is designed so that you can just unplug the device without consequences, but having an error message pop up when clicking "Eject" in Nautilus is kind of unexpected and not really nice.

I tried the following, but failed :

  • Add myself to the fuse group, start go-mtpfs as root and try to unmount as myself
  • Start go-mtpfs as the fuse user and group, and try to unmount as myself, also in the fuse group

Any idea? Also, if you have an elegant way to achieve the same thing without having to rely on the fuse group, I'd love to hear about it!

systemd service (/etc/systemd/system/android-mtp.service) :

ExecStartPre=/bin/mkdir -p /media/Android
ExecStart=/usr/sbin/daemonize -l /var/lock/go-mtpfs.lock /usr/bin/go-mtpfs -allow-other=true /media/Android
ExecStop=/bin/umount /media/Android
ExecStopPost=/bin/rmdir /media/Android

udev rule (/etc/udev/rules.d/99-android-mtp.rules) :

# Google Nexus 7 16 Gb Bootloader & recovery mode
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e40", MODE="0666" # Bootloader
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="d001", MODE="0666" # Recovery

# Google Nexus 7 16 Gb PTP mode (camera)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e43", MODE="0666" # PTP media
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e44", MODE="0666" # PTP media with USB debug on

# Google Nexus 7 16 Gb MTP mode (multimedia device)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e41", MODE="0666" # MTP media
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e42", MODE="0666" # MTP media with USB debug on

# Google Nexus 7 MTP mode : automatic unmount when unplugged (all android versions)
ENV{ID_MODEL}=="Nexus", ENV{ID_MODEL_ID}=="4e41", ACTION=="remove", RUN+="/usr/bin/systemctl stop android-mtp.service"
ENV{ID_MODEL}=="Nexus", ENV{ID_MODEL_ID}=="4e42", ACTION=="remove", RUN+="/usr/bin/systemctl stop android-mtp.service"
ENV{ID_MODEL}=="Nexus_7", ENV{ID_MODEL_ID}=="4e41", ACTION=="remove", RUN+="/usr/bin/systemctl stop android-mtp.service"
ENV{ID_MODEL}=="Nexus_7", ENV{ID_MODEL_ID}=="4e42", ACTION=="remove", RUN+="/usr/bin/systemctl stop android-mtp.service"

# Google Nexus 7 MTP mode : automatic mount when plugged (all android versions)
ENV{ID_MODEL}=="Nexus", ENV{ID_MODEL_ID}=="4e41", ACTION=="add", TAG+="systemd", ENV{SYSTEMD_WANTS}="android-mtp.service"
ENV{ID_MODEL}=="Nexus", ENV{ID_MODEL_ID}=="4e42", ACTION=="add", TAG+="systemd", ENV{SYSTEMD_WANTS}="android-mtp.service"
ENV{ID_MODEL}=="Nexus_7", ENV{ID_MODEL_ID}=="4e41", ACTION=="add", TAG+="systemd", ENV{SYSTEMD_WANTS}="android-mtp.service"
ENV{ID_MODEL}=="Nexus_7", ENV{ID_MODEL_ID}=="4e42", ACTION=="add", TAG+="systemd", ENV{SYSTEMD_WANTS}="android-mtp.service"
share|improve this question
up vote 0 down vote accepted

The fuse group is intended to indicate who can mount FUSE filesystems. The intent is not that anyone in that group can unmount filesystems mounted by others. Only the user doing the mounting, or root, can unmount the filesystem.

You can use sudo to authorize users in the fuse group to run an unmount command as the same user who did the mounting. Run visudo to add a line like:

%fuse ALL = (fuse) fusermount -u /media/Android

Why aren't you doing the mounting as yourself? That's the usual way to use FUSE.

share|improve this answer
But then you'll have to use sudo -u fuse fusermount -u /media/Android every time, right? Would Nautilus (as myself) automatically guess that it can use sudo to unmount? – F.X. Dec 3 '12 at 23:24
@F.X. Yes, you'd have to invoke sudo explicitly. I don't know if Nautilus can be configured to do that. Again, why not do the mounting as yourself? – Gilles Dec 3 '12 at 23:34
Mostly because if it works great, I want to try and package it for the AUR repos in Arch. Which would fail miserably if I have a hard dependency to my username in the udev rules... – F.X. Dec 4 '12 at 11:47
@F.X. Usually physically mounted devices are mounted by the user who is logged in on the console, as tracked by something like PolicyKit (which Arch Linux supports). – Gilles Dec 4 '12 at 12:39
Ah, interesting! I've heard about PolicyKit but never bothered learning much about it. I'll look into it, it seems that it's exactly what I'm looking for. Thanks! I'll keep you posted. – F.X. Dec 4 '12 at 15:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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