Tips to Make Your Server More Secure


Last modified: February 22, 2024

Overview

This document lists several tips that you can use to make your cPanel & WHM server more secure.

Warning:

Exercise caution when you follow these tips. WebPros International, LLC takes no responsibility for modifications to individual servers or the security practices of individual servers. Server security requires that the administrator make compromises, which means that any server that allows connections could contain vulnerabilities.

Use secure passwords

Insecure passwords represent the most common security vulnerability. If a hacker compromises an account password, they can use it to deface or infect client sites, or use them to spread viruses.

Edit the /etc/login.defs file to configure many password options on your system.

Generally, a secure password utilizes at least eight characters, which includes alphanumeric and grammatical symbols. Never use passwords that include dictionary words or significant dates.

If you wish to check a password’s security, test it with JTR cracker. You can also install tools like pam_passwdqc to check the strength of passwords.

Secure SSH

If you move SSH access to a different port, individuals without specific knowledge of your server will not know which port to use for SSH. Many malicious users attempt to use port 22 to access servers. To modify the port on which SSH runs, edit the /etc/ssh/sshd_config file.

We recommend that you use a port number less than 1024 and one that another service does not already use.

  • These ports are “privileged” ports, because only the root user can bind to them.
  • Ports 1024 and above are “unprivileged” ports, and anyone can use them.
Warning:

Always use SSHv2 only. SSHv1 will not properly secure connections. You must change the #Protocol 2,1 line in the /etc/ssh/sshd_config file to Protocol 2.

You may also wish to configure shell resource limits for your users. These limits ensure that applications and scripts cannot use all of your server’s resources and take down your server. You can configure shell resource limits in the /etc/security/limits.conf file on most Linux® systems.

Secure Apache

You must secure your Apache installation. The ModSecurity® tool can help you to secure your server’s Apache installation.

To use ModSecurity to secure Apache, install and enable the Open Web Application Security Project (OWASP) Core Rule Set (CRS). You can do this in WHM’s ModSecurity® Vendors interface (WHM » Home » Security Center » ModSecurity® Vendors).

The OWASP® ModSecurity rule set is a set of rules that Apache’s ModSecurity module can use to help protect your server. While these rules do not make your server impervious to attacks, they greatly increase the amount of protection for your web applications.

You can use the following interfaces to manage ModSecurity:

When you compile Apache, include the suEXEC module to ensure that CGI applications and scripts run as the user that owns and executes them. This module identifies the location of malicious scripts and who executed them. It also enforces permission and environment controls.

We strongly recommend that you compile Apache and PHP with the suPHP module. The suPHP module forces all PHP scripts to run as the user who owns the script. This allows you to identify the owner of all PHP scripts that run on your server and find the location of malicious scripts. To compile Apache and PHP with the suPHP module, select the suPHP option in WHM’s EasyApache 4 interface (WHM » Home » Software » EasyApache 4) or run the /usr/local/cpanel/scripts/easyapache script from the command line.

Finally, we recommend that you implement symlink race condition protection on your server through EasyApache. For more information about the symlink race condition vulnerability and how to protect against it, read our Symlink Race Condition Protection documentation.

Harden your operating system

We recommend that you take steps to harden your operating system to increase its security. Click the links below to access the security guides of supported Linux distributions on which you can install cPanel & WHM:

Harden your tmp partition

Note:

Virtuozzo® and OpenVZ servers do not support this feature.

We recommend that you use a separate /tmp partition and that you mount it with the nosuid option. This option forces a process to run with the privileges of the user who executes it. You may also wish to mount the /tmp directory with noexec after you install cPanel & WHM.

Run the /usr/local/cpanel/scripts/securetmp script to mount your /tmp partition to a temporary file for extra security. The temporary file will use 1% of the available disk space in the /usr partition, from a minimum size of 500MB to a maximum size of 4GB.

Important:

We strongly recommend that you do not disable the /usr/local/cpanel/scripts/securetmp script. However, if you do not wish for your server to run the /usr/local/cpanel/scripts/securetmp script, perform either of the following actions:

  • Run the /usr/local/cpanel/scripts/securetmp script and enter y when the system displays the following prompt:
Would you like to disable securetmp from the system startup?
  • Create the /var/cpanel/disabled/securetmp file. To do this, run the following command:
mkdir -p /var/cpanel/disabled ; touch /var/cpanel/disabled/securetmp
This file ensures that the script can't run on your server.

Restrict the system compilers

Most users do not require the use of C and C++ compilers. We strongly recommend that you disable compilers for all users who do not exist in the compilers group in the /etc/group file. Many pre-packaged exploits require functional compilers.

  • To disable compilers from the WHM interface, use WHM’s Compiler Access interface (WHM » Home » Security Center » Compiler Access).
  • To disable compilers from the command line, run the following command as the root user:
    /scripts/compilers off

Disable unused services and daemons

Any service or daemon that allows connections to your server may also allow hackers to gain access. To reduce security risks, disable all services and daemons that you do not use.

Disable any services that you do not currently use with WHM’s Service Manager interface (WHM » Home » Service Configuration » Service Manager).

Monitor your system

Make certain that you know when a user creates an account. Also make certain that you know what software runs on the server, when software requires updates, and other similar information about your server.

Run the following commands frequently to to ensure that your system functions in the way that you expect:

  • netstat -anp — Check for programs on ports that you did not install or authorize.
  • find / \( -type f -o -type d \) -perm /o+w 2>/dev/null | egrep -v '/(proc|sys)' > world_writable.txt — Check the world_writable.txt file for all of the world-writable files and directories. This command reveals locations where an attacker can store files on your system.
    Note:

    If you fix permissions on some improperly-written PHP and CGI scripts, the script or website may no longer function.

  • find / -nouser -o -nogroup >> no_owner.txt — Check the no_owner file for all files that do not have a user or group associated with them. A specific user or group should own all files, to restrict access to them.
  • ls /var/log/ — Many of the different logs on your system can reveal security issues. Check your system logs, Apache logs, mail logs, and other logs frequently to ensure that your system functions as expected.

Third-party software companies offer readily-available utilities to monitor your system and to detect rootkits, backdoors, or other vulnerabilities.

For example, you could install one of the following commonly-available utilities:

  • Tripwire — Monitors checksums of files and reports changes.
  • chkrookit — Scans for common vulnerabilities.
  • Rkhunter — Scans for common vulnerabilities.
  • Logwatch — Monitors and reports on daily system activity.

Additionally, we recommend that you allow a technical security professional to perform regular configuration checks of your system.

Control access to services by IP Address

You can use WHM’s Host Access Control interface (WHM » Home » Security Center » Host Access Control) to allow only certain IP addresses to access the following services on the server:

  • cPanel (cpaneld)
  • WHM (whostmgrd)
  • Webmail (webmaild)
  • Web Disk (cpdavd)
  • FTP (ftpd)
  • SSH (sshd)
  • SMTP (smtp)
  • POP3 (pop3)
  • IMAP (imap)

You can also configure the /etc/hosts.allow file directly via the command line. To do this, perform the following steps:

  1. Log in to your server as the root user.

  2. Open the /etc/hosts.allow file with your preferred text editor.

  3. Enter the desired rules in the following format:

    service : IP address : action
    

    The following example demonstrates how to allow the 192.168.0.0 IPv4 address to access the cPanel service:

    cpaneld : 192.168.0.0 : allow
    

    The following example demonstrates how to allow the 2001:0db8:0:0:1:0:0:1 IPv6 address to access the cPanel service:

    cpaneld : [2001:0db8:0:0:1:0:0:1] : allow
    
Notes:
  • When you configure your firewall directly, you can use CIDR notation.

  • WHM does not use a hosts.deny file. Add deny statements to the /etc/hosts.allow file.

Enable a firewall

Before you remove all unused services and daemons or disable unused services and daemons, you can enable a firewall to prevent unwanted access. For more information on the ports that cPanel & WHM requires to function properly, read our How to Configure Your Firewall for cPanel & WHM Services documentation.

You may use all of these services or other services, and you should adjust your rules accordingly.

Remember:

Set a cron job to disable your firewall every five minutes while you test your rules, or your server may lock you out.

Prevent email abuse

If your server uses the Secure Mail Transfer Protocol (SMTP), we recommend that you perform actions to prevent email abuse on your cPanel & WHM server. This can prevent hackers from gaining access to your server. For information about how to prevent email abuse, read our How to Prevent Email Abuse documentation.

Stay up-to-date

We strongly recommend that you run the latest stable versions of the software on your system to ensure that it contains patches for any security issues. Be aware of updates for the following:

  • Kernel
  • cPanel & WHM
    • You can set these to automatically update in WHM’s Update Preferences interface (WHM » Home » Server Configuration » Update Preferences).
  • User Applications (bulletin boards, content management systems, blog engines, etc.)
    • You can upgrade all cPAddon installations in WHM’s Manage cPAddons Site Software interface (WHM » Home » cPanel » Manage cPAddons Site Software).
  • System Software
    • You can set these to automatically update in WHM’s Update Preferences interface (WHM » Home » Server Configuration » Update Preferences).

Additional Documentation