I installed apache2 on Ubuntu just now, and noticed that the /var/www folder is protected. I can just sudo everything but I would rather just give it write access.

How can I do this?

I tried sudo chmod 7777 /var/www but it didn't work.

  • Is this a publicly accessible server, or does it have no direct connection to the internet? If the former it is important that you consider security decisions - servers on the internet are constantly under attack (have a look in your /var/log/messages or equivalent).
    – kwutchak
    Aug 7, 2009 at 2:36
  • this is just my laptop, it is not accessible from the internet. Aug 7, 2009 at 3:31

9 Answers 9


To best share with multiple users who should be able to write in /var/www, it should be assigned a common group. For example the default group for web content on Ubuntu and Debian is www-data. Make sure all the users who need write access to /var/www are in this group.

sudo usermod -a -G www-data <some_user>

Then set the correct permissions on /var/www.

sudo chgrp -R www-data /var/www
sudo chmod -R g+w /var/www

Additionally, you should make the directory and all directories below it "set GID", so that all new files and directories created under /var/www are owned by the www-data group.

sudo find /var/www -type d -exec chmod 2775 {} \;    

Find all files in /var/www and add read and write permission for owner and group:

sudo find /var/www -type f -exec chmod ug+rw {} \;

You might have to log out and log back in to be able to make changes if you're editing permission for your own account.

  • 3
    that's pretty tedious... I can't just give users access to it, as if it were any other folder? Aug 7, 2009 at 0:21
  • 12
    That is how you give access to it. It's quicker to copy and paste the commands than try to navigate through a GUI file manager's dialogs to do the same thing. Long term it helps you if you read the manual pages for chmod and chgrp, at least ("man chmod").
    – jtimberman
    Aug 7, 2009 at 1:33
  • 1
    +1 for guid to force apache permissions. works well with umask of 027. If something needs writes access, it's as easy as chmod g+w dir/
    – LiraNuna
    Aug 7, 2009 at 3:47
  • 1
    Why is your group permission command sudo chmod -R g+w and not g+rw or g+rwX?
    – detly
    Aug 31, 2014 at 1:24
  • 2
    How to make a brand new file have w permission for group?
    – vbarbarosh
    Jan 23, 2019 at 15:00


sudo chmod -R a+rw /var/www


sudo chmod -R a+rwx /var/www

There's a simpler way to do this, try doing this command.

sudo chmod -R 757 /var/www

Essentially, the chmod command alters permissions and the -R switch applies to files and directories recursively. Then it is simply giving the correct permissions to use.

  • 3
    Could you give some insight on what the command does for the OP?
    – nopcorn
    Sep 23, 2011 at 5:35
  • 13
    -1 for lack of explanation. Besides, chmod $permissions -R $file isn't valid… Jan 26, 2013 at 16:48
  • 1
    it is options then permissions not the other way around Jan 17, 2014 at 13:52
  • 2
    sudo chmod -R 757 /var/www
    – Bwyss
    Jul 28, 2016 at 21:39
  • 2
    -R is recursive, it's not "affects all users"
    – Alex Yu
    Aug 1, 2021 at 6:58

You can also replicate what jtimberman suggested using access control lists. The setfacl command accepts -s to replace an existing ACL or -m to modify it; -R to make directory ACLs recursive; and -d to make the specified settings the default, which is useful if you're anticipating forthcoming user accounts.

These just set the permissions as you would for the user, group, other, and mask using chmod:

setfacl -m u::rwx, g::r-x, o::---, m:rwx DIRECTORY

And this could be how you'd do it for a specified user or his/her group:

setfacl -m u:USERNAME:rwx, g:USERNAME:r-x DIRECTORY

And of course, the strength is that you can designate any specific user, multiple users, etc., all without having to modify your group settings. And unlike chmod, if you want some groupies to have access to one directory and other groupies to have access only to another, it's actually possible with setfacl. Finally, to view a directory's ACLs, run getfacl:


And you can specify -R to see the ACLs for subdirectories or -d to see the defaults.


The quick & easy answer -

a. Add (-a) your user (user_name) to the group (-G) www-data.

sudo usermod -a -G www-data user_name

b. Give the Group (g) the same (=) permissions as the owning User (u) of /var/www Recursively (-R).

sudo chmod -R g=u /var/www

Explanation: Apache 2 on Debian/Ubuntu sets the User & Group www-data as the Owner of /var/www. The default permissions for the User are "View & Modify Content", however the Group can only "View Content". So adding yourself to the www-data Group and giving it the same permissions as the wwww-data User, is a quick and easy way to get developing. I do this for all my localhost (PC/Laptop) Web Development environments.

  • This is bad for security. The reason www-user was created was for it to be a user with no (or minimal, in the case of files the web server MUST write to) write permissions so that anyone who compromises the web server can't do much damage and can't install custom code. If you give www-user write access to your website that's breaking that open. Use one of the solutions that involves creating a new user group. Dec 14, 2023 at 1:38
  • To clarify, making the files world-writable is similarly a bad idea, hence the recommendation to use a group, just NOT the web server's restricted permissions group Dec 14, 2023 at 1:40

I typicall use

chmod g+w /folder/ -R

It's almost self-explaining.

It adds everyone in the group of /folder/ to have write access (+w) , -R is for recursion for sub-folders.



Open Terminal and Type

chmod ugo+rwx /home/eallen/Downloads


chmod 777 /home/eallen/Downloads

"/home/eallen/Downloads" Replace it with your directory/foldername

if you want to remove all permission then type

chmod -rwx /home/eallen/Downloads

  • 1
    Your answer will be more useful if you were to explain why this would work. Dec 29, 2023 at 11:12

Can you just try chmod 0777 /var/www ?

A word of warning: if you let everybody access this folder, that means the hackers can access this folder if they gain access to your system. That's why it's better to create a group of permissible users, and give that group write access.

  • so why offer this as a solution, and then immediately discredit it? -1 vote
    – Tisch
    Aug 16, 2016 at 12:44

First you enter the particular folder path, then using this command …

chmod -R 777 foldername
chown username:username foldername 
  • 7
    Wow, that's bad! You don't give a 777 with a -R -- especially if the person asking the question is a newbie and doesn't understand the risks.
    – recluze
    Mar 22, 2012 at 7:34
  • True enough @recluze.
    – vgoff
    Nov 12, 2012 at 0:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .