The Computer Oracle

How can I give write-access of a folder to all users in linux?

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Popsicle Puzzles

--

Chapters
00:00 Question
00:40 Accepted answer (Score 362)
01:53 Answer 2 (Score 73)
02:08 Answer 3 (Score 43)
02:32 Answer 4 (Score 9)
03:53 Thank you

--

Full question
https://superuser.com/questions/19318/ho...

Answer 3 links:
[access control lists]: http://en.wikipedia.org/wiki/Access_cont...
[setfacl]: http://linux.about.com/library/cmd/blcmd...
[getfacl]: http://linux.about.com/library/cmd/blcmd...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#linux #permissions #apachehttpserver

#avk47



ACCEPTED ANSWER

Score 373


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.




ANSWER 2

Score 95


Read+Write:

sudo chmod -R a+rw /var/www

Read+Write+Execute:

sudo chmod -R a+rwx /var/www



ANSWER 3

Score 45


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.




ANSWER 4

Score 9


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.