
Your WHM login is the front door to every account on the server. If it’s exposed, everything behind it is at risk.
This cPanel server security tutorial walks you through a realistic hardening pass you can finish in an afternoon. The checks are designed to prevent lockouts and keep customer sites online.
The steps apply to cPanel/WHM on supported Linux builds commonly used for hosting in 2026 (AlmaLinux/Rocky/CentOS Stream). You’ll make most changes in WHM. You’ll also do a few controlled edits under /etc.
What you’ll secure (and what you’ll need)
- WHM/cPanel access: limit who can reach ports 2087/2083 and require stronger authentication
- SSH: remove password auth, reduce exposure, and cut brute-force attempts
- Firewall: expose only the services you actually provide (web, mail, DNS as needed)
- TLS + AutoSSL: prevent the common renewal failures that show up weeks later
- Web app protection: ModSecurity (OWASP CRS) with a test-first rollout
- Backups + restore drills: prove you can recover, not just “back up”
Prereqs: root WHM access, console access via your provider (IPMI/KVM/serial) or at least an out-of-band recovery option, and a maintenance window if you’re changing SSH or firewall rules.
Step 1: Baseline the server before you change anything
Spend a few minutes inventorying what’s listening and what’s critical. This is the easiest way to avoid surprises.
A common example: “mail stopped working” after a firewall tweak.
Check open ports
ss -lntup
Typical cPanel servers show ports like 22 (SSH), 80/443 (web), 2087/2083 (WHM/cPanel), 25/465/587 (SMTP), 110/995 (POP), 143/993 (IMAP), 53 (DNS if you host DNS), and 21 (FTP).
In 2026, avoid FTP if you can.
Confirm cPanel services are healthy
/usr/local/cpanel/scripts/restartsrv_cpsrvd --status
/usr/local/cpanel/scripts/restartsrv_httpd --status
/usr/local/cpanel/scripts/restartsrv_exim --status
Record the current hostname and reverse DNS expectations
hostnamectl
dig +short -x $(curl -s ifconfig.me)
Mail deliverability depends on your hostname and rDNS lining up. If you already see bounces, keep this near the top of your fix list.
(For rDNS, see: Reverse DNS Setup Tutorial (2026).)
Step 2: Lock down WHM and cPanel access paths
Most opportunistic attacks start by hammering WHM, cPanel, or webmail logins. The fastest win is to make those endpoints unreachable to people who don’t need them.
Restrict WHM access by IP (best win, least risk)
If you manage the server from a fixed office or VPN IP, whitelist it at the firewall. That alone cuts a lot of risk.
If you’re often mobile, you can still restrict WHM (2087). Keep cPanel (2083) available to customers, then add extra controls.
If you use ConfigServer Security & Firewall (CSF), add your IP to /etc/csf/csf.allow and reload:
# Example: allow your admin IP
203.0.113.10
csf -r
If you don’t run CSF, use your OS firewall (nftables/firewalld). For a production ruleset approach, follow: iptables-nftables tutorial (2026).
Force HTTPS redirects for cPanel services
In WHM: Service Configuration → Service Manager confirm cpsrvd is enabled. Then review:
- Service Configuration → cPanel Service Configuration → Service SSL Certificates
- Verify services use valid certificates and don’t sit on self-signed certs longer than necessary
Disable unused access surfaces
- Disable FTP if possible. Use SFTP instead.
- Disable legacy protocols (plain POP/IMAP) and require the SSL/TLS ports.
- Remove demo/test accounts and any old reseller accounts you no longer use.
For a clean SFTP posture, see: VPS SFTP Setup Guide Tutorial (2026).
Step 3: Enforce 2FA and tighten authentication policies
Passwords leak, get reused, and get phished. Add a second factor wherever you can.
Start with WHM.
Turn on WHM/cPanel 2FA
In WHM: Security Center → Two-Factor Authentication
- Enable 2FA for root and all admin/reseller accounts first.
- Roll it out to customer-facing accounts after you confirm your support process.
Follow a lockout-safe process here: cPanel Two-Factor Authentication Tutorial (2026).
Reduce brute-force success rates (cPHulk)
In WHM: Security Center → cPHulk Brute Force Protection
- Enable protection for cPanel, WHM, Webmail, and SSH (where appropriate).
- Start with conservative thresholds so customers don’t lock themselves out repeatedly.
- Whitelist your monitoring and office/VPN IPs.
For a rollout that minimizes lockouts, use: cPanel Brute Force Protection Tutorial (2026).
Step 4: Harden SSH (without locking yourself out)
SSH is where people get stranded. Don’t make changes in a single session and hope for the best.
Keep one session open. Test the new login in a second window.
Create or confirm a sudo-capable admin user
adduser adminops
usermod -aG wheel adminops # RHEL-family
# or: usermod -aG sudo adminops # Debian/Ubuntu
Even if you normally work as root on cPanel servers, a named admin account improves auditing. It also reduces “oops” mistakes.
Install your SSH key and test it
From your workstation:
ssh-copy-id adminops@YOUR_SERVER_IP
ssh adminops@YOUR_SERVER_IP
Disable password authentication
Edit /etc/ssh/sshd_config (or a drop-in under /etc/ssh/sshd_config.d/ if your distro uses it). Set:
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
PermitRootLogin prohibit-password
Then validate and reload:
sshd -t
systemctl reload sshd
Optional: move SSH to a high port (only if your workflow supports it)
Port changes mostly cut log noise. They do not replace real authentication controls.
If you change ports, update firewall rules first. Make sure console access is ready.
Use a lockout-safe runbook like: SSH Port Change Tutorial (2026).
Step 5: Put a real firewall policy in place (minimum required ports)
A cPanel server isn’t a generic Linux host. If you block mail or DNS ports without thinking, you’ll create outages.
Decide what the server actually does. Then open only what matches that role:
- Web hosting only: 80/443, 2083/2087 (restricted), 22 (restricted)
- Web + mail: add 25/465/587 and 110/995/143/993
- Authoritative DNS: add 53 TCP/UDP
Quick checklist: ports you should question
- 21 (FTP): avoid unless you must support legacy clients
- 2052/2082 (unencrypted cPanel): should not be exposed
- 3306 (MySQL): keep local-only unless you have a documented remote DB need
Confirm firewall matches cPanel service needs
After applying changes, verify access from an external network. Don’t test from the server itself.
# From your workstation
nc -vz YOUR_SERVER_IP 22
nc -vz YOUR_SERVER_IP 2087
nc -vz YOUR_SERVER_IP 443
Step 6: Fix AutoSSL and TLS settings so renewals don’t fail later
Most AutoSSL failures are self-inflicted. Common causes include broken DNS, blocked validation paths, or a proxy/CDN that never passes DCV requests through.
Run an AutoSSL check for a single domain
In WHM: SSL/TLS → Manage AutoSSL then run a check. If it fails, don’t guess.
Check the DCV method. Then read the exact failure reason.
For the most common renewal failures (DCV errors, mixed HTTPS, validation path problems), use: cPanel AutoSSL Troubleshooting Tutorial (2026).
Confirm TLS protocols and ciphers are sane
In WHM: Service Configuration → Apache Configuration → Global Configuration review TLS settings if you’re using Apache, or your web server stack. Many cPanel environments run LiteSpeed as well.
Either way, treat TLS changes as “set, then verify.” Schedule a quick recheck after updates.
Step 7: Enable ModSecurity (OWASP CRS) with a safe rollout plan
ModSecurity blocks real exploit traffic. It can also block legitimate requests if you enable aggressive rules everywhere on day one.
Roll it out in phases. Let logs drive your tuning.
Phase 1: enable ModSecurity in detection-only for a subset
In WHM: Security Center → ModSecurity™ Vendors, enable OWASP CRS, then start with one or two lower-risk accounts. Watch logs before you expand coverage.
If you want a step-by-step that focuses on not breaking WordPress, use: cPanel ModSecurity Setup Guide Tutorial (2026).
Phase 2: tune exclusions per application, not globally
- Scope rule disables to a domain or location whenever possible.
- Fix app behavior (bad plugins, unsafe upload endpoints) before weakening the WAF.
- Log every exclusion as a change so you can audit and roll it back later.
Step 8: Patch safely with staged updates and rollback checks
On hosting servers, “update everything right now” is how you break PHP extensions, mail filters, and billing integrations.
Use a predictable update channel. Patch when you can watch the box.
Set update preferences
In WHM: Server Configuration → Update Preferences
- Use staged rollout where possible.
- Schedule updates during a window when you can monitor and respond.
- Enable notifications for failures.
For the complete staged update workflow, follow: WHM Update Preferences Tutorial (2026).
Run OS updates in a controlled way
# AlmaLinux/Rocky/CentOS Stream
dnf -y update
reboot
If you can’t reboot immediately, record kernel/glibc updates and schedule the restart. Patches that never get loaded don’t reduce risk.
Step 9: Backups that restore cleanly (and a quick restore drill)
Hardening without recovery is wishful thinking. “Backups exist” isn’t the goal.
“We restored successfully” is.
Configure WHM backups with remote storage
In WHM: Backup → Backup Configuration
- Enable backups and set retention to match your business risk.
- Use remote destinations so a single-server compromise can’t wipe your backups.
- Include account backups and system configuration where appropriate.
Use this runbook for a production-grade setup: cPanel Backup Configuration Tutorial (2026).
Run a fast restore drill (one account)
- Create a small test account and add a file + mailbox.
- Force a backup run.
- Restore that account to a staging VPS (preferred) or a temporary restore directory.
- Verify: web files, database connection (if used), mailbox content, and SSL.
If you want a structured verification approach, see: VPS Backup Verification Tutorial (2026).
Step 10: Practical monitoring signals that catch compromises early
Hosting compromises usually leave clear trails. Look for spikes in outbound mail, new cron jobs, sudden disk growth, or unusual PHP processes.
You don’t need a full SIEM to catch the first wave of problems.
Minimum alerts worth setting up
- Disk usage > 80% (and inode usage)
- Load average above your normal baseline for 10+ minutes
- Outbound email queue growth (Exim queue depth)
- Unexpected restarts of cpsrvd/httpd/exim
- Certificate renewal failures
A simple setup that works well for VPS and dedicated servers: Server Monitoring Setup Guide Tutorial (2026).
Hardening checklist (printable)
- Access: Restrict WHM by IP; enforce 2FA for admins/resellers
- Brute force: Enable cPHulk with sane thresholds; whitelist trusted IPs
- SSH: Key-based auth; password auth off; root login limited
- Firewall: Only required ports open; no public MySQL; review FTP need
- TLS: AutoSSL passing; service certs valid; renewals monitored
- WAF: ModSecurity enabled; phased rollout; domain-scoped exclusions
- Patching: WHM Update Preferences set; OS updates scheduled; reboots planned
- Backups: Remote destination configured; at least one restore drill completed
- Monitoring: Disk/load/mail queue/cert alerts enabled
Where HostMyCode fits (VPS and managed operations)
If you’re building a more secure hosting stack in 2026, start with a VPS that gives you clean isolation and predictable resources. A HostMyCode VPS is a solid base for cPanel/WHM, custom firewall rules, and remote backups.
If you’d rather not spend your week chasing patch windows and baseline tasks, managed VPS hosting can handle routine maintenance. You still keep control of accounts and customers.
Need a cPanel-ready VPS with enough headroom for ModSecurity, malware scanning, and remote backups? Start with a HostMyCode VPS and keep the stack under your control.
If you want the same foundation with help for patching, monitoring, and incident-response basics, consider managed VPS hosting from HostMyCode.
FAQ
Will enabling ModSecurity break WordPress logins or WooCommerce checkout?
It can if you enable aggressive rules globally without testing. Roll it out per account, review audit logs, and add targeted exceptions only for confirmed false positives.
Should I change the WHM port from 2087?
Changing ports doesn’t buy much by itself. IP restriction plus 2FA and strong passwords deliver the real benefit. If you do change it, document it for staff and monitoring.
Is disabling SSH password authentication safe for customer servers?
Yes, as long as you confirm key-based logins work for every admin and you have console access for emergencies. Keep one session open while you test a second login.
What’s the fastest way to reduce successful brute-force attempts?
Restrict WHM to known IPs, enable 2FA for privileged users, and turn on cPHulk with sane thresholds. Those three changes shut down most opportunistic attacks quickly.
Summary: a secure baseline you can maintain
This cPanel server security tutorial focused on controls that stay useful month after month. Reduce exposed surfaces. Require strong authentication.
Run a tight firewall. Keep TLS renewals healthy. Prove your backups restore.
Once these are in place, day-to-day operations tend to get quieter.
If you’re ready to apply this on production infrastructure, deploy it on a HostMyCode VPS or move to dedicated servers when you need full isolation and consistent performance for many accounts.