I'm on Debian 8. While How to set default file permissions for all folders/files in a directory? is about permissions, I'd like something similar for ownership.

Whenever I login as root and add a file to a daemons config directory, the ownership of the newly created file is root:root. While this is OK for most situation, here it isn't. I'd like to have the ownership set to daemon:daemon automatically when I create a file somewhere under the config directory.

How do I accomplish that?

2 Answers 2


You can't.

You can use chmod to set the sticky bit on a directory (chmod g+s directory/) and that will cause all files created in the directory to be in the same group as the directory itself. But that only affects the group, not the owner.

You can also set your umask or ACLs on the directory to affect the default permissions of files created.

But you can't automatically set the owner of a file you (root) created to some other user. You have to do that with chown.

You're just going to have to get used to the chown, chgrp, and chmod commands.


You can also have a look at this answer if that helps. Possibly a cronjob that runs every 30 secs can immediately change permissions as you create file as 'root' user.

  • 1
    Such an idea creates a window for a race condition.
    – vonbrand
    Oct 25, 2015 at 13:14
  • What if I exchange cron with inotify?
    – bot47
    Oct 26, 2015 at 15:32

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.