Description
This document will be focused on helping you setup a secure web hosting environment on a Centos VPS (Virtual Private Server). For other Linux or Unix-like systems many of the actual configuration options will be similar or identical but some file names, file paths, commands, etc may be different depending on the operating system. Therefore, instructions for your particular system may vary. It does not matter what operating system you use, only that you are comfortable and familiar with it. You’re free to adapt the instructions here to your setup or search for something more specific on the Internet.
Purpose & Scope
This document starts from scratch and assumes you have just received or setup a new VPS with Centos Linux on it and have done no configuration yet. The theory here is to start in a very restrictive state and selectively allow access to the required services or functionality as needed. In this way, we’re not unnecessarily exposing ourselves to potential threats before we’ve had a chance to properly setup the environment.
Mandatory Setup
- Secure sshd
- Create user accounts / groups (usermod, useradd, userdel, groupadd, groupdel)
- Filesystem permissions (chmod)
- Filesystem ownership (chown)
- Sudo Configuration (visudo)
- Generate 4096 Bit RSA public/private encryption keypair
- Installation and configuration of SELinux
- Netfilter IPtables / IP6Tables firewall rules
- Installation and configuration of Fail2ban
- Installation and configuration of Denyhosts
- Enable Network Time Protocol ntp/ntpdate
- Set system timezone, Example:
ln -sf /usr/share/zoneinfo/America/Los_Angeles /etc/localtime
- Installation and configuration of Apache httpd
- Installation and configuration of nginx
- Installation and configuration of PHP-FPM
- Installation and configuration of SSL/TLS certificates
- Installation and configuration of mod_security
- Installation and configuration of mod_evasive
- Installation and configuration of mod_ssl
- Installation and configuration of MariaDB / MySQL
- Database container setup
- Database dumps and backups
Filesystem
Networking
Webserver
Database
Optional Setup
These things are not necessary but will certainly help you in your day to day management of the server and/or clients by providing useful stats, log analysis, secure file-sharing and database management.
Post Setup Options
- Installation and configuration of AWStats – Website analytics and detailed visitor statistics.
- Installation and configuration of iCinga – Open source, scalable, enterprise-level system monitoring and notification tools.
- Installation and configuration of Log Analyzer – Visual system log analyzer.
- Piwik Analytics – Extendable open source self-hosted web analytics platform, Free, 100% data ownership, user privacy protection.
Secure Filesharing Solution
- Installation and configuration of Own Cloud – Secure self-hosted DropBox-like solution. 100% data ownership and control.
- Installation and configuration of PHPmyAdmin – Web front-end for MySQL / MariaDB.
- Backup script written for Bash – Backup important directories and files (system configuration, webroots, databases, system log files).
- chkrootkit – Scan the system for rootkits, suspicious changes, files or other malicious behaviours.
- rkhunter – Scan the system for rootkits, suspicious changes, files or other malicious behaviours.