A security enhancement toolkit for protecting SSH access to public-facing servers.
This project provides a comprehensive solution for securing SSH access to public-facing servers, particularly focusing on scenarios with dynamic IP addresses. It combines firewall rules, DDNS (Dynamic DNS), and automated scripts to create a robust security system.
- Dynamic IP-based access control
- Automated firewall rule updates
- Support for multiple firewall systems (UFW, firewalld, iptables)
- Detailed logging system
- DDNS integration
- A registered domain name (free or paid)
- Root access to your server
- One of the supported firewalls (UFW, firewalld, or iptables)
- Basic understanding of Linux system administration
Modify your SSH configuration for better security:
vim /etc/ssh/sshd_config
# Recommended settings
Port <unusual-port> # Change from default port 22
PasswordAuthentication no # Disable password login
PubkeyAuthentication yes # Enable key-based authentication
Choose one of the following methods based on your firewall:
UFW:
ufw allow from <client-ip> to any port <ssh-port>
Firewalld:
firewall-cmd --zone=public --add-rich-rule='rule family="ipv4" source address="<client-ip>" port protocol="tcp" port="<ssh-port>" accept' --permanent
Iptables:
iptables -A INPUT -p tcp --dport <ssh-port> -s <client-ip> -j ACCEPT
For users with dynamic IPs, this project provides an automated solution:
-
Set up DDNS for your domain using tools like:
-
Use the provided script (
ufw-reddns-ssh.sh
) to automatically update firewall rules based on your domain's IP. -
Set up a cron job to run the script periodically.
-
Edit the script variables:
DOMAIN
: Your domain namePORT
: Your SSH portLOG_FILE
: Path to log file (default: /var/log/ufw_update.log)
-
Make the script executable:
chmod +x ufw-reddns-ssh.sh
- Add to crontab for automatic execution:
crontab -e
# Add line: */5 * * * * /path/to/ufw-reddns-ssh.sh
The script maintains detailed logs at /var/log/ufw_update.log
, including:
- IP address changes
- Firewall rule updates
- Current firewall status
- Timestamps for all operations
This project is licensed under the MIT License - see the LICENSE file for details.