I’m facing a permissions issue when changing ownership of a folder on Ubuntu and I could use some assistance.
My goal is to have both "ubuntu" and "www-data" with appropriate permissions on the folder "/var/www/immogate.tn/public_html". I want "ubuntu" to remain the owner while granting permissions to "www-data".
www-data is my apache user that needs to uplad files in the folder and execute them
ubuntu is my SFTP user.
Any help or insights into this issue would be greatly appreciated. Thank you in advance for your assistance!
Best regards,
Here’s the problem I’m encountering:
I initially run the following commands:
sudo chown -R ubuntu:ubuntu /var/www/immogate.tn/public_html
sudo chown -R www-data:www-data /var/www/immogate.tn/public_html
After executing these commands, the user "ubuntu" retains its permissions, but the user "www-data" takes ownership of the folder. However, when I reverse the order of the commands like this:
sudo chown -R www-data:www-data /var/www/immogate.tn/public_html
sudo chown -R ubuntu:ubuntu /var/www/immogate.tn/public_html
The opposite happens—now "ubuntu" takes ownership, while "www-data" loses its permissions.
2
Answers
Try this
First you must add the ubuntu user to the www-data group:
Then navigate to the public_html folder:
Now change the ownership of the files and folder as follows:
And then change the file permissions.
First for all folders:
And then for all files:
At least set the group sticky bit for all folders:
This will ensure that files/folders created by the user ubuntu will belong to ubuntu:www-data and files/folders created by the user www-data will belong to www-data:www-data.