Setting up your storage, security, and permissions (Simple)
As mentioned earlier, partitioning is very important for a web server. You already took your first steps by selecting which directories you wanted partitioned out (hopefully, at least /tmp
and /var
or /var/www
), but now you need to set security and permissions for them.
Getting ready
If you will have several profiles for users and groups, this is a good time to review them as you prepare to harden the storage permissions. On Unix systems, everything is a file, and a lot of the security measures depend on filesystem security.
How to do it…
At root, open /etc/fstab
with a text editor. Towards the end of it, you will see lines for the partitions you created during installation.
You can see that we have the /tmp, /var/lib/mysql and /var/www folders partitioned out. In most cases, you won't need to mess with the first column which is the device name (the installer figured it out for you), but you must make sure that:
The mount points are right
The filesystem in use is the one you want (Debian uses ext4 by default, although many others are available)
The mount options are right: noatime or relatime (doesn't write to the disk every time the access time changes, which speeds things up. Frankly it's not very useful on web servers, although some Unix tools will expect this behavior), noexec (disallows executable files), nodev (no special device files allowed), and nosuid (no files with elevation of rights enabled)
You will close an important set of attack vectors by applying this basic security measure, as most attackers rely on the /tmp
folder being world writeable to drop and run malicious scripts there. Also, /var
contains /var/www
and /var/lib/mysql
or /var/lib/postgres
, which will benefit from that security measure as well.
Permissions are also important. On Debian, the Nginx and Apache processes run as a system user called www-data. This user must have read permissions for your application scripts and static files that most likely will be sitting on /var/www
. But unless your application allows uploads or edits to that folder, you don't need write permissions. The following two operations can help you reset permissions:
chown –R www-data:www-data /var/www # resets owner and group to www-data chmod –R a-w /var/www # removes write permissions for all users on www-data
For MySQL and PostgreSQL, Debian usually defaults to the right thing (/var/lib/mysql
is owned by MySQL) when it comes to storage permissions.