ubuntu is the name of default system user in an Ubuntu system. On the other hand
www-data is the user and group name that web servers on Ubuntu (Apache, nginx, for example) use by default for normal web server operations. It also means that the web server processes can access any file that
www-data can access.
Due to the difference in name and group access the default
ubuntu user may not perform file write operation inside your web root folder or the folders which require
www-data ownership rights. For example the
ubuntu user cannot pull changes from a github repository to your web root folder etc.
This is default behavior in an Ubuntu system and we do not need to worry about it. However in some cases, you may wish to do some file create or write operations inside your web root folder. So here we are.
In this simple tutorial we will give
ubuntu user access to
www-data group so that the
ubuntu user could do file write operations on folders under web root directory.
Adding ubuntu user to www-data group
ubuntu user to
sudo usermod -a -G www-data ubuntu
Optional – if user (user with any other name) does not exist do this additional step to add user:
sudo adduser [username] www-data
Important step: Make sure all files are owned by the
www-data group and user (refreshes the ownership settings)
sudo chown -R www-data:www-data /var/www
Enable all members of the
www-data group to read and write files:
sudo chmod -R g+rw /var/www
Important: Unto this step, you should be all set to perform file write operations such as
git pull as
ubuntu user. But, probably, may wish that all files created in this directory (in future) would listen to the current ownership settings. If you do not do it, you will have to set file ownership manually every time you create new file or folder under your project root.
To enable automated permission granting, run the following:
sudo chmod -R g+rws /var/www
Logout and login back as user
ubuntu to see new permissions in effect.
In this Linux tutorial we have learned how to add
ubuntu user to
www-data group to fix write permission errors occurring due to the mismatch between name and permissions of current user
ubuntu and web server group