Check User (Expected: root):
sudo whoami
Deactivate root:
sudo nano /etc/ssh/sshd_config
Change "#Port 22" to "Port 2244".
Change "PermitRootLogin" to "PermitRootLogin no".
Change "PubkeyAuthentication" to "PubkeyAuthentication yes".
Change "PasswordAuthentication" to "PasswordAuthentication no".
Expected no response:
sudo sshd -t
sudo systemctl stop ssh.socket && sudo systemctl disable ssh.socket && sudo systemctl restart ssh
sudo ufw allow 2244/tcp && sudo ufw delete allow 22/tcp && sudo ufw delete allow OpenSSH && sudo ufw reload && sudo ufw status
sudo passwd -l root && sudo systemctl restart ssh
Check Config:
sudo grep "^Port" /etc/ssh/sshd_config
Check Errors:
sudo sshd -t
Change SSH Active Port:
sudo systemctl stop ssh.socket && sudo systemctl disable ssh.socket && sudo systemctl restart ssh && sudo ss -tulpn | grep ssh
Clear Firewall:
sudo ufw delete allow OpenSSH && sudo ufw delete allow 22/tcp && sudo ufw reload
Install Fail2Ban:
sudo apt update && sudo apt install fail2ban -y && sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local && sudo nano /etc/fail2ban/jail.local
Change:
[sshd]
enabled = true
port = 2244
filter = sshd
logpath = /var/log/auth.log
maxretry = 3
findtime = 10m
bantime = 1h
sudo systemctl restart fail2ban
New Terminal (DON'T CLOSE THIS ONE!): SSH with port 2244
ssh -p 2244 @