14

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.

SONGE
  • 143
  • You're sure your user has write permissions to /var/www without becoming root (e.g. using sudo)? – David Bailey May 27 '15 at 10:33
  • @DavidBailey I have write permissions to /var/www but not to the subfolders. I've done chown on /var/www but when I've checked permissions on subfolders, ex. /var/www/First_Site, it belongs to www-data. I thought that chown on a main folder will give me permissions also to all subfolders/files in it. – SONGE May 27 '15 at 12:12

7 Answers7

7

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:

  1. 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 to 774 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.
  2. 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.

  3. 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.

Oli
  • 293,335
  • You are right. I have only rights to /var/www folder, but not to all subfolders in it, which belongs to www-data. I think the best solution here will be to add my user to www-data group. – SONGE May 27 '15 at 12:04
  • Just to let anyone know. Adding my user to www-data group solved the problem. I just had to reboot the system after this. Thank you @Oli. – SONGE May 27 '15 at 13:36
6

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.

anonymous2
  • 4,298
0

Perform the following in your Linux/Unix terminal:

sudo chmod -R 777 project-name
sudo chown user-name project-name

Tried -R 775 and didnt work so -R 777 did the trick although I have given write permissions to all project

0

Add your current user to www-data group.

$USER already has the current user or you can change it for another user.

sudo usermod -a -G www-data $USER

Change permissions.

cd /var/www/Your_Project
sudo chown -R www-data:www-data .
sudo find . -type f -exec chmod 664 {} \;
sudo find . -type d -exec chmod 775 {} \;
alditis
  • 341
0

a quick solution would be to add your user to the www-data group with root user (sudo command):

usermod -a -G www-data your_username

Check if it is there:

grep ^www-data /etc/group

And do not forget to restart your system

Youssef
  • 101
0

Add your user to administrator user group by one of the below based on the version of Ubuntu you're using. Try both:

sudo usermod -a -G admin username

OR

sudo usermod -a -G sudo username

If you're already in the admin group try a chown on the folder.

0

I have the same issue, trying to edit my apache server's file with sublime-text and I don't want to mess up my webserver's permission. Changing your files g+w and putting your user in www-data group is not a very safe idea.

What I would advise is using SFTP plugin for sublime-text:

  • duplicate your webserver's file to a folder belonging to your own user
  • configure SFTP plugin with:
"upload_on_save": true,
"host": "localhost",
"user": "www-data",

Do not provide a password in the configuration for this is a major security hole too.

Sublime-text will ask you for the password once and then will remember it for the session. Upon each file save, it will open an sftp session to localhost and will write the file to disk with the appropriate user