I have search around but can't find the correct answer.

How do I change the permission of a directory and all its sub-directories/files then also when a user creates a file or directory this must also follow the same permissions set at the beginning.

Basically this is what i want to do:

Keep in mind I am running a Ubuntu Server 16.04.3 with 2 virtual hosts (so 2 separate IP's used)

  1. create a new virtual host (i have completed this)
  2. create a new directory /var/www/example (i have completed this)
  3. created new group and user with the same name(as i wanted to mimic the same as www-data user and group.)
  4. change ownership of directory: -- used command: sudo chown -R user:group /var/www/example (this change the owner to my desired owner and group owner)

  5. set permissions of this directory to 775 -- used command: sudo chmod -R 775 /var/www/example (this changed the permissions)

after all of these done i am still able to use a user to create a file which is good as this user is in the group i created but the thing is that the permissions are all wrong and the file owner is also wrong. (the user i used is also part of another group that is used on the other virtual host).

Please guide me to a solution. thanks

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.