using m2.2.2 here. file and folders belongs all to www-data user and group, then I have another user that belongs to the same group. When this last user runs php bin/magento commands, the frontend breaks saying "can't write folder", and I have to go as root and give again chown www-data:www-data . -r command (sometimes more than once, tbh).
I don't understand why and how to solve this.
Can you confirm if your current configuration match with the documentation? http://devdocs.magento.com/guides/v2.2/config-guide/prod/prod_file-sys-perms.html