I am running a digital ocean droplet with Ubuntu 16.04.3.

One of the folders is designated for FTP uploads. Access to this folder is limited to an upload user called transferuser

There is another folder called dataFolder which where transferuser has no permissions.

When logged in as root, if I copy everything from the FTP folder to the dataFolder, permissions on the copied files are still specific to only transferuser.

How can I set permissions on a folder so that any file copied to that folder then gets those same permissions?

  • 1
    when you say permissions are specific to transferuser, do you mean that transferuser is still the owner of the files, and you want root (or some other user) to be the owner?
    – Zanna
    Aug 24 '17 at 16:07

When you copy with root privileges (running the command with sudo), and use the option to preserve the permissions and ownership, you should get what you want.

From man cp:

   -p     same as --preserve=mode,ownership,timestamps

          preserve the specified attributes (default: mode,ownership,time‐
          stamps), if  possible  additional  attributes:  context,  links,
          xattr, all

The following command line will copy files in the folder but no subdirectories

sudo cp -p source-folder/* target-folder

The following command line will copy files in the folder as well as subdirectories and files in them (recursively)

sudo cp -pr source-folder/* target-folder

You can also use rsync for this task (preserving the permissions including subdirectories)

sudo rsync -Ha source-folder/ target-folder

where the -H means that it will also manage hard links (optional).

If this is not what you want, but you want to change the ownership or permissions, please explain with details what you want.

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.