Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
    
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 '09 at 2:36
    
this is just my laptop, it is not accessible from the internet. –  Carson Myers Aug 7 '09 at 3:31
2  
Wow, my first gold badge on any SE site, and I didn't notice it for two months :/ –  Carson Myers Jul 30 '11 at 0:29
add comment

6 Answers

up vote 129 down vote accepted

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.

share|improve this answer
2  
that's pretty tedious... I can't just give users access to it, as if it were any other folder? –  Carson Myers Aug 7 '09 at 0:21
4  
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 '09 at 1:33
    
perhaps I didn't understand the commands the first time I read it, and your edit makes it much more clear. –  Carson Myers Aug 7 '09 at 3:39
    
+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 '09 at 3:47
    
Just wanted to chime in and say this is awesome advice that is very concise and simple to follow while explaining everything you need to know. Well said. Upvoted and starred for future use. :) –  Kyle Sep 19 '12 at 10:09
show 3 more comments

there's a simple way..! try this

sudo chmod 757 -R /var/www
share|improve this answer
    
Could you give some insight on what the command does for the OP? –  MaxMackie Sep 23 '11 at 5:35
1  
-1 for lack of explanation. Besides, chmod $permissions -R $file isn't valid… –  Blacklight Shining Jan 26 '13 at 16:48
    
it is options then permissions not the other way around –  Moataz Elmasry Jan 17 at 13:52
add comment

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:

getfacl DIRECTORY

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

share|improve this answer
add comment

Read+Write:

sudo chmod -R a+rw /var/www

Read+Write+Execute:

sudo chmod -R a+rwx /var/www
share|improve this answer
add comment

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.

share|improve this answer
add comment

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

chmod -R 777 foldername
chown username:username foldername 
share|improve this answer
3  
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 '12 at 7:34
    
True enough @recluze. –  vgoff Nov 12 '12 at 0:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.