Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

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
share|improve this answer

First, I think we talk about to change the owner and not the permissions.

When you copy a file it will be recreated in the target folder. Thats why the files will have your account as owner. You can't create files with account X and the owner Y.

But you can of course change the owner of the files after you copied them.

As your user X type:
chown <accountY>:<accountY> /path/to/file.test

Or recoursive for changing the owner of a folder and all files within:
chown -R <accountY>:<accountY> /path/to/folder

This will the change the owner and group of the files/folder.

share|improve this answer
    
I sort of had this as an answer, then changed it to ACL but that does not work well with USB and removed that. It is technically not what he wants: he wants it on the fly. Your answer does not work if he copies files over that have more than 1 owner... What he probably needs is rsync. –  Rinzwind Apr 24 '13 at 8:00
    
@ Rinzwind: Sounds like you know what he wants and you have a solution for this problem. Why don't you post an answer? –  prophecy201 Apr 24 '13 at 8:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.