This problem happens when the php user does not have permission to work with the folder on the server ( maybe it is var or pub folder ).
In the magento 2 some times you often run ssh command line with the root user and it create some new folders and filse with root owner.
You can change owner or change permission for them to solve the problem.
Change owner by using the ssh command line:
sudo chown -R www-data:www-data ./var sudo chown -R www-data:www-data ./pub
Change permission by using the ssh command line:
sudo chmod -R 777 ./var sudo chmod -R 777 ./pub