0

I'm using an encrypted (cryptsetup with LUKS with ext3) SD-Card as disk space extension. When entering the key in Nautilus, the device is decrypted (/dev/dm-3) and mounted in /media/$USER/. Unfortunately the owner is root. How can I permanently change the ownership of the mounted device under /media/$USER?

I already tried the following udev rule:

ENV{ID_FS_UUID}=="a1d9e412-fd9d-4e44-a98f-d0d6f2de83c2", SUBSYSTEM=="block", OWNER="david"

But it did not work out.

Is it possible to have a dynamic ownership so that the OWNER is set to the user who tries to mount the device?

0

You are confusing concepts here. Your udev-rule change the ownership of the device node of the disk. This is completely independent from the ownerships and permissions of the file-system entries of the contained file-system.

Basically, there are two kinds of file-systems: Those who know the concept of file-ownership, like the common UNIX filesystems (ext[2-4], XFS, JFS, Btrfs, …); and those who don't, like at least the »old« Windows/DOS filesystems (FAT*).

The kernel's file-system drivers for the latter ones usually have mount-options to tell the kernel which owner and permissions to present to user-space, as Linux is a multi-user system and users need to be separated — as need their files, even on external drives. When you mount a file-system without the concept of file-ownership, Nautilus & Co. usually use these mount-options to make the files »owned« by your user (resp. usually the owner of the currently active session).

With file-systems having a concept of file-ownership (as ext3 you use), things are different. As files on this file-systems have explicit owners, the kernel honours them. Those file-systems also do not offer a mechanism (like mentioned mount-options) to override this behaviour, as it would breach security. Thus, if you mount such a file-system, even through Nautilus, the kernel will honour the actual file-ownerships.

tl;dr: Changing the block devices owner to your user does not solve (or even advance to) the problem. There is no way to make the kernel behave as if the owner of the files is you, but you'll need to actually make you the owner, i.e. by using chmod. This operation will be permanent though, as you change the file-system itself. This will make this approach unsuitable for e.g. repairing a system-partition of another computer.

If it is okay (or intended) to change the ownership permanently and you have root access to the system where you want to use your device, you could just do chown -R <user> /media/<user> as root after the file-system is mounted.

But note, that if you have different systems and your accounts' UIDs don't match on all systems, you will have the same problem on the next machine again. In this case, you could either change your accounts' UIDs to match (if you have the rights), or you could format your device with a file-system unaware of ownership, like FAT32.

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.