22

I have tweaked the permissions on /media/username from root:root to username:root [1]. I understand that a user-centric location allows user-centric permissions [2].

But why were the permissions for this folder root:root in the first place?


[1] So that I can mount encrypted folders there with Gnome EncFS Manager. For example, I can now mount an encrypted folder as /media/username/personal-documents.

[2] From Why has Ubuntu moved the default mount points? :

The root cause for this change of default behaviour in udisks2 seems clear : the security. It is safer to restrict access to a file system to one particular user instead of giving access to it to all the users of the system.

1
  • Mounting usually involves root access. You can (as you did) tweak the permissions. However this can by no means become "default" behaviour in Linux. Imagine what will happen if any user (not an admin) has the ability to mount like you did. This will be a total chaos. :) Jan 18, 2014 at 10:51

3 Answers 3

23
+100

In my case this is how things look in /media:

$ ls -l /media | grep $USER
drwxr-x---+  3 root root 4096 Jan 22 15:59 oli

Basically this means that only a root user can interact with the directory. This is great for security (certainly stops other users seeing, let alone stealing/deleting/changing data) but that's not where the story ends.

You might notice the plus sign at the end of the permission mask. This means an ACL (Access Control List) is in use. This allows for far more granular permissions.

$ getfacl /media/$USER
getfacl: Removing leading '/' from absolute path names
# file: media/oli
# owner: root
# group: root
user::rwx
user:oli:r-x
group::---
mask::r-x
other::---

It's through ACL where my user is allowed to view the contents of /media/oli. I'm still not allowed to edit the contents.

The thing doing the mounting in modern desktops (both Gnome and KDE) is udisks2:

root      2882  0.3  0.0 195956  4048 ?        Sl   Jan16  30:35 /usr/lib/udisks/udisks-daemon
root      2887  0.0  0.0  47844   784 ?        S    Jan16   0:00 udisks-daemon: not polling any devices
root      3386  0.0  0.0 429148  6980 ?        Sl   Jan16   7:35 /usr/lib/udisks2/udisksd --no-debug

As you can see, it's running there as root, so when something accesses it over DBUS, it's able to create the mount-points within /home/$USER and chown them down to your user so they can edit the contents.

None of that changes what I said originally. I'm just explaining how it works in practice. This is how something on your desktop is in-effect allowed to write somewhere that is only allowed by root, and how your user is allowed to read it despite an otherwise restrictive ownership.

All that turns it into an environment that is secure for the user's data but one that also makes it hard for the user to meddle with the fabric of the mount. They can't, for example, delete the mount-point or rename it which could cause issues unless they have root access.

Edit: Something that just occurred to me is that it also gives an administrator a good place to mount things for a single user. The permissions by default help keep this mount private and protect this mount against the user's meddling. It seems like a fairly sane default for something that done without the /media/$user/ directory, would need root permissions.

2

I agree to the other answer and comments in addition to that

root:root to avoid mainly two situations.
1. Security risk : A hacker script which dump /dev/zero to /media/user/ which fill the root partition and hence unable to login or bad performance.
2. Conflict with udisk2 : Assume a partition with label backup. Udisks mount it @ /media/user/backup . user manually created the above directory which will force the udisk to change mount point to something like /media/user/backup1 and thus misleaded by backup scripts etc.

2

The Linux (and *nix) mentality in general is based on the principle of Least amount of necessary privileges.

Usually modern Desktop Environments will mount your devices under /media/username/devicepartitionname. This means that for the device to be usable you only need to own the devicepartitionname folder and anything below it. This means that your folder of /media/username could still be owned by root, and that would make it more secure.

Also mounting anything on /media/username is a bad idea, as that will make your DE try to mount a partition into a folder on another mounted partition which can lead to a lot of !!FUN!! (also probable data loss).

4
  • thanks for a simple but not simplistic answer ... I've clarified above that GnomeEncFS is mounting to /media/username/someplace not /media/username ... you specifically say it should be owned by root, would root:username be better than username:root in my case? or do they both introduce the same security concern? (see this question for why I have to do it anyway askubuntu.com/questions/392063/… )
    – lofidevops
    Jan 17, 2014 at 9:49
  • @d3vid : Depends, in the second case if you hadn't changed the default permission your normal user wouldn't be able to write to /media/user (as it's 750) which is a tad bit better than the first case. As for the mounting: historically the /mnt and its subfolders are considered to be the default mount point for anything, the /media was only added so that people who just want to use a linux box without actually understanding how things work won't get confused by all the strange folders and whatnot on /.
    – Wolfer
    Jan 17, 2014 at 18:27
  • @d3vid : As for the security concern: it's because folders that you have write access and execute access to can be used by a hacker / cracker / whatever you want to call him / her to upload binaries that they can then use to gain root access to your box. (This is called privilege escalation.) Although you shouldn't make your system deliberately more insecure there are default places that allow the same thing (and are more obscure and as such make less likely the hackers activity to be found). So the "security concern" in this case could be ignored depending on your setup.
    – Wolfer
    Jan 17, 2014 at 18:37
  • 1
    @Wolfer - I've rolled back to a version of your answer than does not contained deemed offensive language. Lets try to keep Q&A's as clean as possible and try not to cause any offence. Thanks.
    – fossfreedom
    Apr 23, 2014 at 22:38

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.