6

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?

bot47
  • 1,268

2 Answers2

9

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.

cas
  • 78,579
-2

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.