vscode always ask for permission to save

Make sure that you (as an Ubuntu user account) are the owner of the folder and files you are editing in VSCode:

cd /path/to/my/files
chown -R $USER:$USER .

Note: If you are not the user, you might have to precede that with sudo:

sudo chown -R $USER:$USER .

(Note: full stop makes you the owner of the files in the parent directory)


This is a common problem. You don't want to change the owner:group of your files and you don't want to run VSCode as root for security reasons. Here's my solution, with a little background info. On a typical web server, the web files will be owner:group www-data:www-data (for example) - only the owner (www-data)has write permission. VSCode runs under the $USER account, not www-data, so it has no write permission. You can't change VSCode to run as www-data (not easily) so the alternative is to add $USER to the www-data group, and give the folders write permission for the group. This is only a little less secure than the group having only read permissions - acceptable in my view on a development machine. Add yourself to the www-data group:

sudo usermod -aG www-data $USER

This won't take effect immediately, you need to su to yourself then logout and back in

su $USER

Check that you're in the www-data group

id

Logout and in again. Next, change the permissions on /var/www/html (or wherever you're trying to write to):

sudo chmod -R ug+rw /var/www/html
sudo chown -R www-data:www-data /var/www/html

Re-start VSCode and your user should now have write permissions for the folder. If for any reason you accidentally change directory permissions, you can restore them with:

sudo find /var/www/html -type d -execdir chmod 750 {} +

sudo chmod -R 777 filename works for the file's parent folder.