Fixing the www-data user on Ubuntu (AWS EC2)

I feel like the user www-data is broken. You can’t SSH, you can’t even switch user to www-data without running a special command. (I’ve got another blog page on that). Here’s how to create a www user to replace the www-data user on Ubuntu. We obviously use AWS EC2.

Create the www user and home directory

Change Nginx config to use www instead of www-data

Change the line user www-data to user www then save and exit.

Change PHP-FPM config to use www instead of www-data

sudo vim /etc/php/5.6/fpm/pool.d/www.conf

The version could be 5.6, 7.0, 7.1 or something else depending on what PHP version you’re running in your LEMP stack. We’ll assume it is 5.6 for this tutorial.

Find lines that say:

and lines that say:

Change www-data to www

Fix the /var/lib/nginx directory

We need to ensure that the user www has full write access to /var/lib/nginx

Restart the services

Create SSH key

Switch user to www

Create the SSH key

Add the public key to authorized_keys

It’s all done!

The setup is complete at this stage. Just ensure that you’re always using www for your web files and all your web files and directories are set to www:www – sometimes you’ll need to move directories to /home/www if you have existing files in other home directories and you may have to run chown too depending on whether you have existing web files or not. Feel free to ask any questions below!


Write a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.