Defensive Configuration
SSH Configuration Hardening
1. Disable Root Login
Prevent direct root login to minimize unauthorized access risks:
## Edit SSH configuration
sudo nano /etc/ssh/sshd_config
## Set the following parameter
PermitRootLogin no
2. Implement Key-Based Authentication
graph LR
A[Client SSH Key] --> B[Server Authorized Keys]
B --> C{Authentication}
C -->|Key Matches| D[Secure Access]
C -->|Key Mismatch| E[Access Denied]
Generate SSH key pair:
## Generate SSH key
ssh-keygen -t rsa -b 4096
## Copy public key to remote server
ssh-copy-id username@remote_host
Configuration Option |
Recommended Setting |
Purpose |
MaxAuthTries |
3 |
Limit login attempts |
LoginGraceTime |
30 |
Restrict connection time |
AllowUsers |
specific_userlist |
Control user access |
4. Implement Firewall Rules
## UFW configuration
sudo ufw limit ssh
sudo ufw enable
5. Install Fail2Ban
Automatically block repeated failed login attempts:
## Install Fail2Ban
sudo apt-get update
sudo apt-get install fail2ban
## Configure SSH jail
sudo nano /etc/fail2ban/jail.local
## Example configuration
[sshd]
enabled = true
port = ssh
filter = sshd
logpath = /var/log/auth.log
maxretry = 3
bantime = 3600
Advanced Protection Strategies
Rate Limiting
- Implement connection throttling
- Use tools like
iptables
for sophisticated filtering
Two-Factor Authentication
- Integrate additional authentication layers
- Utilize tools like Google Authenticator
Security Best Practices
- Regularly update SSH configuration
- Monitor authentication logs
- Use strong, unique passwords
- Implement principle of least privilege
At LabEx, we emphasize proactive and comprehensive SSH security configurations to protect your infrastructure effectively.