2

I am deploying some custom software as root (a necessity for this situation).

I set the owner/group to user1:user1 and set all the files to 644 beforehand in shell, then copy and deploy with ant.

However, when files get copied over from the deployment directory, the ownership changes back to root and all the files install with 666 permissions.

This seems to occur whether the file is overwritten or newly created. I believe there is a way to set an option in cp, mv commands to preserve permissions, but that would be a lot of commands to change. How can I fix this?

Is there some setting I can change temporarily for root so the install always preserves the file permissions?

  • Are you using a script with lots of cp and mv commands? If yes it should be easy to change all of them with sed to use the options you need (see my answer below). – Claudio Jul 10 '12 at 16:12
  • Yes I have a number of cp/mv commands, but they are occuring in my ant deploy.xml, so not shell script. – yellavon Jul 10 '12 at 19:54
2

cp -p will preserve your permissions. If you want the copy to be the closest possible you can simply use the "archive" option: cp -a. From cp --help you can double check it:

-a, --archive                same as -dR --preserve=all

-p                           same as --preserve=mode,ownership,timestamps
  --preserve[=ATTR_LIST]   preserve the specified attributes (default:
                             mode,ownership,timestamps), if possible
                             additional attributes: context, links, xattr,
                             all
0

No. But you should be using install instead, which lets you explicitly specify all that.

  • 1
    Can you expand on that? Google didn't turn up any good explanations or examples. – yellavon Jul 11 '12 at 13:56

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.