Sublime Text 3 authentication question when saving document
I am using Sublime Text for web developement. Every time I try to save changes (Ctrl+S), the authentication window pops up:
Authentication is needed to run '/bin/cp' as the super user
Obviously, when I enter the password, Sublime saves changes correctly. But when I press Cancel, another window pops up with an error:
Error: administrator_copy_file (/tmp/.Some_File_Here, /var/www/Rest_Of_Path_Here) failed: Authorization failed
As I am quite new to Ubuntu I don't know how to get rid of that authorization pop up. I have all permissions to /var/www folder.
Solution 1:
You don't have permission to write to /var/www/Rest_Of_Path_Here
. ST3 is trying to elevate its UID to write as the correct user (hence the sudo prompt). I didn't know it could do this but I've tested it and it works so there you go.
There are a few ways you can fix this:
-
Allow your user to write the files directly. So many options here:
-
chown
the files so you own them. This may upset things running as other users that might also need to write, eg a webserver running as www-user. You may need to change what they run as too. - Add your user to the
www-data
group and change the file mask to774
so members of the group can write/execute. - Change the file mask so other users can write (eg 777)... But this is pretty risky if there's something malicious on the server already.
- Use ACLs to allow your user to write without disturbing the standard permissions framework.
-
Change your workflow to write into a version control system (eg git) as your users, and then have a script running as the other user check it out. This carries other benefits.
-
Run ST3 as a user who can write there:
sudo -u www-data subl /var/www/Rest_Of_Path_Here
This is quite a lot uglier than just fixing the files.
Solution 2:
I had the same issue and was able to solve it by providing user right to the particular folder which I had to edit in Sublime text 3. I used the following commands:
sudo chmod 775 -R projectname/
sudo chown username -R projectname/
I think it might be helpful to others in future.