Overview
This guide covers how to secure services and fix common vulnerabilities detected on your VPS. Services like MySQL, PostgreSQL, Redis, and web servers may be configured to accept connections from any IP address, creating security risks.
Database Vulnerabilities
MySQL
Issue: MySQL is accepting connections from all IP addresses (0.0.0.0)
Solution:
1. Open the MySQL configuration file:
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf2. Update the bind address:
bind-address = 127.0.0.13. Restart the service:
sudo systemctl restart mysqlPostgreSQL
Issue: PostgreSQL is listening on all network interfaces
Solution:
1. Edit the PostgreSQL configuration:
sudo nano /etc/postgresql/*/main/postgresql.conf2. Update the listen addresses:
listen_addresses = 'localhost'3. Restart the service:
sudo systemctl restart postgresqlMongoDB
Issue: MongoDB is publicly accessible
Solution:
1. Edit the MongoDB configuration:
sudo nano /etc/mongod.conf2. Update the network binding:
net:
bindIp: 127.0.0.13. Restart the service:
sudo systemctl restart mongodRedis
Issue: Redis is bound to all interfaces
Solution:
1. Open the Redis configuration:
sudo nano /etc/redis/redis.conf2. Update the bind address:
bind 127.0.0.13. Ensure protected mode is enabled:
protected-mode yes4. Restart the service:
sudo systemctl restart redisSearch and Caching Services
Elasticsearch
Issue: Elasticsearch is accepting external connections
Solution:
1. Edit the Elasticsearch configuration:
sudo nano /etc/elasticsearch/elasticsearch.yml2. Set the network host:
network.host: 127.0.0.13. Restart the service:
sudo systemctl restart elasticsearchMemcached
Issue: Memcached is listening on all interfaces
Solution:
1. Edit the Memcached configuration:
sudo nano /etc/memcached.conf2. Update the listen address:
-l 127.0.0.13. Restart the service:
sudo systemctl restart memcachedWeb Server Vulnerabilities
HTTP Server Information Disclosure
Issue: Web server is exposing version information and sensitive details
Apache
1. Edit the security configuration:
sudo nano /etc/apache2/conf-available/security.conf2. Add or update:
ServerTokens Prod
ServerSignature Off3. Disable directory listing:
<Directory /var/www/>
Options -Indexes
</Directory>4. Restart Apache:
sudo systemctl restart apache2Nginx
1. Edit the Nginx configuration:
sudo nano /etc/nginx/nginx.conf2. Add inside the http block:
server_tokens off;3. Restart Nginx:
sudo systemctl restart nginx<h2″>SSL/TLS Vulnerabilities
POODLE Vulnerability (SSLv3)
Issue: Server allows vulnerable SSLv3 protocol
Apache
1. Edit SSL configuration:
sudo nano /etc/apache2/mods-available/ssl.conf2. Update SSL protocols:
SSLProtocol all -SSLv3 -TLSv1 -TLSv1.13. Restart Apache:
sudo systemctl restart apache2Nginx
1. Edit site configuration:
sudo nano /etc/nginx/sites-available/default2. Add or update in server block:
ssl_protocols TLSv1.2 TLSv1.3;3. Restart Nginx:
sudo systemctl restart nginxFREAK Vulnerability (Weak Ciphers)
Issue: Server allows weak export-grade cipher suites
Apache
1. Edit SSL configuration:
sudo nano /etc/apache2/mods-available/ssl.conf2. Update cipher suite:
SSLCipherSuite HIGH:!aNULL:!MD5:!EXP:!LOW:!MEDIUM3. Restart Apache:
sudo systemctl restart apache2Nginx
1. Edit site configuration:
sudo nano /etc/nginx/sites-available/default2. Add or update:
ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384';
ssl_prefer_server_ciphers on;3. Restart Nginx:
sudo systemctl restart nginxAuthentication and Secrets
Bad Secrets / Weak Credentials
Issue: Default credentials, weak passwords, or exposed secrets detected
Database Credentials
Change MySQL user password:
mysql -u root -pALTER USER 'username'@'localhost' IDENTIFIED BY 'NewStrongPassword123!';
FLUSH PRIVILEGES;Environment Files
1. Find exposed .env files:
sudo find /var/www -name ".env" -type f2. Secure permissions:
sudo chmod 600 /var/www/your-site/.envBest Practices
- Use passwords with minimum 12 characters
- Include uppercase, lowercase, numbers, and symbols
- Rotate API keys regularly
- Use a password manager
Mail Server Security
SMTP Open Relay / Authentication Issues
Issue: Mail server may be configured as an open relay or lacks proper authentication
Postfix
1. Edit the configuration:
sudo nano /etc/postfix/main.cf2. Add or update:
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
smtpd_tls_security_level = may
smtpd_tls_auth_only = yes3. Restart Postfix:
sudo systemctl restart postfixExim
1. Edit the configuration:
sudo nano /etc/exim4/update-exim4.conf.conf2. Update relay networks:
dc_relay_nets='127.0.0.1'3. Apply changes:
sudo update-exim4.conf
sudo systemctl restart exim4Firewall Configuration
Additional Security Layer
Allow SSH and enable firewall:
sudo ufw allow ssh
sudo ufw enableAllow remote access from trusted IP only:
sudo ufw allow from <YOUR_IP> to any port 3306Verification
Test SSL/TLS Configuration
Visit: https://www.ssllabs.com/ssltest/
Check Open Ports
sudo netstat -tulnReview Active Services
sudo systemctl list-units --type=service --state=running