Ubuntu – www-data related: What’s the difference between these usages of CHOWN

Apache2chownpermissions

My user name is jknoppf. I use Apache and want to give myself full access to /var/www/html and start with

$ sudo adduser jknoppf www-data

Then I have

$ sudo chown -R www-data:www-data /var/www/html

It works!

But on some forums I have also read about

$ sudo chown -R jknoppf:www-data /var/www/html

And it also works! What is the difference between these two variants of using chown?

Best Answer

sudo adduser jknoppf www-data and sudo chown -R www-data:www-data /var/www/html:

The first one will add the user jknoppf into the group www-data, and the second one will change the owner of all the directories and files, including /var/www/html, into the user www-data, and also change the group owner into the group www-data. Since the permission for /var/www/html is by default 775, and the user jknoppf is in the group www-data, this user can have full access to all the contents inside.


sudo chown -R jknoppf:www-data /var/www/html:

This command change the owner of all the directories and files, including /var/www/html, into the user jknoppf, and also change the group owner into the group www-data. Since the permission for /var/www/html is by default 775, and the user jknoppf is the owner of the directory, this user can have full access to all the contents inside.


Remarks: the permission 775 means:

First 7: the owner of the file have full access to files, i.e. read 4 + write 2 + execute 1.

Second 7: all users in the group, which the group is owner, have full access to files, i.e. read 4 + write 2 + execute 1.

Third 5: all other people that are neither the owner nor the members of the group only have access to read 4 + execute 1.