skip to Main Content

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


  1. Try this

    $ sudo chown -R public_html
    $ sudo chgrp -R www-data public_html
    $ sudo chmod -R ug+rwx public_html
    $ sudo usermod -a -G www-data YourUbuntuUserName
    
    Login or Signup to reply.
  2. First you must add the ubuntu user to the www-data group:

    sudo usermod -a -G www-data ubuntu
    

    Then navigate to the public_html folder:

    cd /var/www/immogate.tn/public_html
    

    Now change the ownership of the files and folder as follows:

    sudo chown -R ubuntu:www-data .
    

    And then change the file permissions.
    First for all folders:

    find . -type d -exec sudo chmod 775 {} ;
    

    And then for all files:

    find . -type f -exec chmod 664 {} ;
    

    At least set the group sticky bit for all folders:

    find . -type d -exec sudo chmod g+s {} ;
    

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search