Ubuntu – Copying files and inherit permissions of target folder

permissions

When I copy files to a USB disk or another account on the same disk the permissions are not changed to the target. For example, when I copy files from account X to a folder of account Y, than the permission on the files are still of account X.

I like to copy files and change the permissions to that of account Y.

How do I do this?

Best Answer

You can use ACL and the command setfacl for that.

ACL Entries

ACL entries consist of a user (u), group (g), other (o) and an effective rights mask (m). An effective rights mask defines the most restrictive level of permissions. setfacl sets the permissions for a given file or directory. getfacl shows the permissions for a given file or directory.

Defaults for a given object can be defined.

ACLs can be applied to users or groups but it is easier to manage groups. Groups scale better than continuously adding or subtracting users.

This is the part you are after:

Copying an ACL into the Default ACL

Once the ACLs are the way they need to be, they can be set as the default. Defaults are inherited, so a new directory will inherit the defaults of the parent directory.

getfacl -a /path/to/dir | setfacl -d -M- /path/to/dir

You do need to add the acl option when mounting. In /etc/fstab add acl to the options for your disc. Make sure to use a LABEL and not a UUID.

LABEL="ExternalUsbDisc"   /media/usb-disc     ext4   defaults,acl   0   2
Related Question