This question already has an answer here:
I am testing a Drupal site on Google Compute Engine. I have a problem with file permissions.
I would like to be able to access and edit my files trough SFTP and still have Drupal functioning as it's supposed to.
Letts say my user for SFTP is 'user'. If I do sudo chown user:www-data -R /var/www/ I can edit files via SFTP. But then I can not make changes or add files in Drupal (for example add a new module trough Drupal, even clearing caches doesn't seem to work).
If I do sudo chown www-data:www-data -R /var/www/ evrything in Drupal works, but I can not make changes to files trough SFTP.
I have tried adding both users ('user' and 'www-data') to a group called 'drupal' and running the command sudo chgrp drupal -R /var/www/ but this doesn't fix the problem.