8

I'm new to Linux admin'ing. I created a user named webadmin and I want to give it permission to read/write in the /var/www/html directory.

How do I go about doing this?

Shamoon
  • 901
  • 4
  • 14
  • 22

1 Answers1

12

Personally, I would set the ownership of /var/www/html to apache. You can do this by:

chown apache /var/www/html

Next, I would create a group of let's say "Web admins":

groupadd webadmins

Add the user webadmin to the newly created group:

usermod -G webadmins webadmin

Add group permissions to the newly created group:

chmod g+rw /var/www/html 
Richardp
  • 184
  • 1
  • 2
  • 14
  • 1
    and also you can create ACL. – Luciano Facchinelli Sep 12 '11 at 00:54
  • On Debian-based distributions, this approach will fail as they run Apache as user/group `www-data:www-data`, not as `apache` by default. – Sven Sep 12 '11 at 01:16
  • Note that files and directories created by a user will be owned by the user's primary group. In order to preserve these group permissions for users who don't have apache as their primary group, you should also set g+s on the directory (and any pre-existing subdirectories). This will ensure that any file created underneath, regardless of who creates it or what their memberships are, are owned by the same group that owns the directory they're created under. – jgoldschrafe Sep 12 '11 at 02:06
  • 1
    I don't have permission to "comment" yet so I'll just expand on @Richardp's answer to save anyone from following blindly and then having to undo later (my own newbie mistake!). In case `webadmin` needs to be in multiple groups, don't forget the `-a` flag: `usermod -a -G webadmins webadmin` -- and regarding @jgoldschrafe's comment, in case you want to modify only directories, `sudo find . -type d -exec chmod g+s {} \;` – Joe Corneli Mar 05 '13 at 15:22