How to give ubuntu user permission to write to www directory

If you are using sftp client to quick edit few files on your web server you must have face the issue of not having permission to edit files.

This can be quickly fixed in 2 steps:

  1. Adding the ubuntu user to the www-data group
  2. Giving write permission to everyone in this group

Adding the user:

Run this command to add the ubuntu user to the www-data group

sudo addgroup ubuntu www-data

You have to logout and login back again for changes to take effect.

Give the write permission:

Assuming your web directory is /var/www we run following command to give everyone in the www-data group write permission to this directory

sudo chmod g+w /var/www -R

Try editing or creating new file in /var/www directory to verify