How user accounts, rights and ownership work in Linux

One area that causes confusion is mount points permissions. It makes absolutely no difference what permissions and ownership are set on a mount point before a filesystem is mounted there, as it acquires the permissions of the root directory of the filesystem that you mount.

How you change things for the top-level directory of a filesystem depends on its type. In the case of Linux filesystems, this is simple: mount it and then use chmod or chown to set it up as you want. These settings will then apply whenever you subsequently mount that filesystem.

Windows filesystems, such as FAT on USB sticks, are treated differently. FAT has no concept of file ownership and NTFS has a system that's incompatible with Linux permissions, so the filesystem driver imposes default permissions.

These generally set all files and directories as owned by the user that mounted the device, otherwise you couldn't write to it. The file permissions usually default to rwxr-xr-x (or 755 if you prefer) by the automounter.

mount

Running the mount command on its own shows the options a filesystem was mounted with. Here you see the mask setting for a FAT formatted USB stick.

If you are mounting a filesystem manually, then use the uid option to set up the appropriate ownership rights and umask for default permissions, like this:

sudo mount /dev/sdb1 /mnt/removable -o uid=john,umask=022

The umask is subtracted from 777 to give the permissions, 755 in this case. A umask of 0 will enable all permissions.

TOPICS