Debian – Is giving all permissions to www-data group a good idea

apache-httpddebianpermissionsSecurity

I constantly have problems with read & write & execute permissions by Apache/me. There is a user "konrad" (it's me) in "konrad" group, and there is a user "www-data" in "www-data" group used by Apache. When I ("konrad") create a directory, then Apache have no rights to write to this folder which causes problems.

So now I have the following "idea": I will add myself ("konrad" user) to the "www-data" group (where also Apache's user belongs) and then I chown all my www projects, so that they will belong to user "konrad" but group: "www-data". And I will chmod the projects so that this group will have all permissions to files and directories (I think that would be 770).

Then I will change my primary group from "konrad" to "www-data", so everytime I'll create a new directory/file Apache will also have a full access to it.

The question is: is this a good idea? I don't have a great experience with permissions or even Unix itself. So maybe I'm missing something. But it seems reasonable to me.

Best Answer

Apache runs as a non-privileged user known as www-data in Debian distros for quite a very good reason: security.

It is considered a good security practice when dealing with daemons giving up privilege rights, avoiding as much as possible to create configuration files or data files with the ownership of the non-privileged user that runs the daemon - as such, if the Apache user is compromised, the attackers will have a much more hard time to mess around things or deface a site.

As possible, I recommend to create sites with different users, and to give read rights to the www-data group only; and to have only write access to www-data in directories that really need them. However even this can be avoided using mod-ruid2.

mod-ruid2 allows actually to run each site/vhost with their owner, and dealing with the security model of pages is much easier. It takes out the necessity of creating world writable directories. It also guarantees that in case of a compromise of one vhost, the attacker is not able to plant malware in the other vhosts.

mod-ruid2 is also advised for people with a hosting model, and we use it here to run a few hundreds sites, with quite success.

Unfortunately, the documentation about mod-ruid2 is a bit scant, and I had to write a more elaborate post to describe it here in Unix and Linux.

Related Question