🔒Enhancing SSH Security for a Validator
Securing SSH access is critical to protecting your validator. This guide covers essential security measures to minimize the risk of unauthorized access.
1. Changing the Default SSH Port
By default, SSH runs on port 22, making it an easy target for attacks. Changing it to a non-standard port improves security.
Open the SSH configuration file:
sudo nano /etc/ssh/sshd_configFind the line:
#Port 22Change it to something like:
Port 2222Save changes (Ctrl + X → Y → Enter) and restart SSH:
sudo systemctl restart sshd
Important: Make sure the new port is allowed in your firewall.
sudo ufw allow 2222/tcp2. Disabling Password Authentication
Using passwords makes your server vulnerable to brute-force attacks. SSH keys provide better security.
Generating SSH Keys
On your local computer (not the server), run:
ssh-keygen -t ed25519 -C "[email protected]"This creates private (~/.ssh/id_ed25519) and public (~/.ssh/id_ed25519.pub) keys.
Adding the Key to the Server
Copy the public key to your server:
ssh-copy-id -p 2222 user@your_serverOr manually:
cat ~/.ssh/id_ed25519.pub | ssh -p 2222 user@your_server "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"Disabling Password Authentication
Edit the SSH config:
sudo nano /etc/ssh/sshd_configFind and change:
PasswordAuthentication noRestart SSH:
sudo systemctl restart sshd3. Restricting SSH Access to Specific Users
Limit SSH access to selected users for additional security.
In /etc/ssh/sshd_config, add:
AllowUsers validator_userRestart SSH:
sudo systemctl restart sshd4. Enabling Two-Factor Authentication (2FA)
Adding 2FA enhances security with an additional authentication step.
Install Google Authenticator:
sudo apt install libpam-google-authenticatorRun the setup:
google-authenticatorFollow the instructions and scan the QR code in the Google Authenticator app.
Enable 2FA in SSH: Edit
/etc/pam.d/sshdand add:auth required pam_google_authenticator.soIn
/etc/ssh/sshd_config, enable challenge-response authentication:ChallengeResponseAuthentication yesRestart SSH:
sudo systemctl restart sshd
5. Limiting Failed Login Attempts
Use Fail2Ban to protect against brute-force attacks.
Installing and Configuring Fail2Ban
sudo apt install fail2ban -yCreate a configuration file:
sudo nano /etc/fail2ban/jail.localAdd:
[sshd]
enabled = true
port = 2222
maxretry = 3
findtime = 600
bantime = 3600Restart Fail2Ban:
sudo systemctl restart fail2ban6. Restricting SSH Access by IP (Whitelist)
If you have a static IP, restrict SSH access to that IP only.
Edit /etc/hosts.allow:
sshd: 192.168.1.100Block all other IPs in /etc/hosts.deny:
sshd: ALL7. Configuring the Firewall (UFW)
Close unnecessary ports and allow only the SSH port you set.
sudo ufw allow 2222/tcp
sudo ufw enableCheck firewall status:
sudo ufw status verbose8. Monitoring SSH Access
Check active SSH sessions:
whoView login attempts:
sudo cat /var/log/auth.log | grep "Failed"Now your SSH access is well-protected. The key security measures include SSH keys instead of passwords, 2FA, Fail2Ban, and firewall rules.
Last updated