I want to stop having to use
sudo everytime I work in
/var/www. How can I do that? I simply want to put all of my sites into this directory and work with them without too much pain.
Most answers here are not written with security in mind. It's good to get a feeling that running
Note: Starting with Apache 2.4.7 / Ubuntu 14.04,
NOTE: in the below solutions, I've granted
Where possible, do not grant write permissions to the
Add yourself to the
Correct previously created files (assuming you to be the only user of
(even safer: use
Create a symlink for each project to your home directory. Say your project is located at
If your home directory has no execute bit (descend) set for
Set the group to
Even safer: use 640 and 2750 by default and manually chmod files and directories that need to be writable by the webserver user. The setgid bit should be added only if you want every newly created file in
From now on, you can access your site at
Rather than storing my web sites in /var/www I place links there to the sites which are located in my home folder. I can freely edit, or add pages to my sites. When I happy with changes I then FTP to a hosting company where my domain name links.
If you make /var/www writeable by its group and add yourself to the group, you will not have to use sudo while still being fairly secure. Try this:
The first line adds you to the www-data group, the second line clears up any files with messed up ownership, and the third makes it so that all users who are members of the www-data group can read and write all files in /var/www.
You could start a www-session in a terminal by
Combined with a differently colored prompt*, to make it more obvious that it is the shell of a different user, and a policy always to put the corresponding xterm (and editor and such) on - for example - the virtual desktop 4, so that you get used to it, to avoid confusion.
*) For a differently colored prompt with a differnt character, create a file /etc/prompt like this:
and source it from
As additional tool to help distinction, you could always edit your files with an alias 'edit' or a symlink, which points, depending on your identity (taylor/www-data) to either gedit or mousepad, vim or pico. Or you could use different editor profiles, at least in gedit you may set your preferences to black text on white ground or white text on black ground for instance.
I only have such a policy for working as root, so I'm not sure how good it will fit to working with www-data. Combined with ssh-sessions to differnt hosts, which have their own prompts, it didn't stop me from being sometimes wrong, but if it happens, I realize fast, what is wrong, and it happens rarely.
note: The prompt-script is partly a copy of the manpage of bash.
chmod in /var on www to allow the owner access, and chown to make sure you own it. Probably a stupid idea, but it would definitely work.
In complement of sagarchalise, I suggest you to first change your group :
Then by replacing /var/www by your own folder :
The /var/www folder neads to be owned by your user. So, you have to do this:
If you want to change the permission of a folder you can also run gksudo nautilus (opens the filemanger with root privileges), navigate to the folder and change the settings under properties permission to what you need.