Ubuntu – How to mount an image file without root


I have a file with an ext4 file system in it and want to mount it without using sudo every time (the script should run with user rights). The file I want to mount and the folder which I want to mount it too both are in my home directory which is encrypted, so I can't put the file location into /etc/fstab.

I tried fusermount but I always get error messages like "fusermount: extra arguments after the mountpoint".

Best Answer

You can use udiskctl:

$ udisksctl loop-setup --file your_file.iso
Mapped file your_file.iso as /dev/loop6.

Now, your file is mapped to a block device, and you can mount it as:

$ udisksctl mount -b /dev/loop6
Mounted /dev/loop6 at /media/user/your_file.

when you're done, unmount is using:

$ udisksctl unmount -b /dev/loop6
Unmounted /dev/loop6.

finally, delete it by:

$ udisksctl loop-delete -b /dev/loop6

Have fun!