VPS security basics
Essential steps to protect your virtual server from hacks and malware.
Your VPS is your server — security is entirely in your hands. Most breaches don't come from provider-level vulnerabilities; they happen because of outdated software, weak passwords, exposed services, or malicious code sneaking in through FTP, plugins, or compromised local machines.
How servers typically get compromised
-
Outdated CMS/plugins
Automated scanners crawl the web looking for WordPress, Joomla, OpenCart, etc., running old versions or vulnerable plugins. Once found → malicious code (iframes, redirects, miners) gets injected. -
Compromised FTP credentials
Malware on your local computer steals FTP logins/passwords → attacker logs in and drops code directly into files. -
.htaccess manipulation
Attackers rewrite .htaccess to redirect visitors to phishing/malware sites or run hidden scripts. -
Uploaded malicious files
PHP files disguised as images get uploaded to/uploads,/images, etc. → executed when accessed.
Core security measures (implement these immediately)
-
Strong passwords & SSH keys only
- Root/admin password: 16+ random characters
- Disable password login in SSH — use keys exclusively:
sudo nano /etc/ssh/sshd_config # Change or add: PasswordAuthentication no PermitRootLogin prohibit-password # or no sudo systemctl restart ssh
-
Keep everything updated Run daily::
sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y -
Correct file permissions
- Files: 644
- Folders: 755
- wp-config.php / configuration.php: 600
find /var/www/ -type f -exec chmod 644 {} \; find /var/www/ -type d -exec chmod 755 {} \;
-
Firewall — allow only what you need UFW example (22/SSH, 80/HTTP, 443/HTTPS):
sudo ufw allow OpenSSH sudo ufw allow 80/tcp sudo ufw allow 443/tcp sudo ufw enable sudo ufw status -
Fail2Ban — stop brute-force attacks Install:
sudo apt install fail2ban -yIt auto-bans IPs after repeated failed login attempts (works out-of-the-box for SSH).
-
Malware scanners & rootkit hunters
- ClamAV — file scanner::
sudo apt install clamav clamav-daemon -y sudo freshclam sudo clamscan -r /var/www- Rkhunter — rootkit/malware detector:
sudo apt install rkhunter -y sudo rkhunter --update sudo rkhunter --check- Lynis — security audit:
sudo apt install lynis -y sudo lynis audit system -
Backups — your safety net
- Daily automated backups (not just on the server — copy to local/cloud)
- Test restores regularly
- If infected → clean restore is faster than manual cleanup
If your site/server is already compromised
- Isolate disable the site temporarily (rename index.php or block via .htaccess)
- Change all passwords (FTP, CMS admin, SSH, database, control panel)
- Scan (ClamAV + Rkhunter + manual check)
- Manual inspection::
- Recently modified files:
find /var/www/ваш_сайт/ -type f -mtime -7 -ls- PHP files in uploads/images:
find /var/www/ваш_сайт/uploads/ -type f -iname "*.php"- Suspicious code patterns:
grep -ril "base64_decode\|eval\|gzinflate\|fromCharCode" /var/www/ваш_сайт/ - Restore from clean backup
- Update CMS/plugins/themes
- Check .htaccess for redirects/iframes
Help
If you have any questions or need assistance, please contact us through the ticket system — we're always here to help!