$ -weight: 500;">apt -weight: 500;">update && -weight: 500;">apt -weight: 500;">upgrade -y
-weight: 500;">apt -weight: 500;">update && -weight: 500;">apt -weight: 500;">upgrade -y
-weight: 500;">apt -weight: 500;">update && -weight: 500;">apt -weight: 500;">upgrade -y
adduser amine
usermod -aG -weight: 600;">sudo amine
adduser amine
usermod -aG -weight: 600;">sudo amine
adduser amine
usermod -aG -weight: 600;">sudo amine
ssh-keygen -t ed25519 -C "[email protected]"
ssh-keygen -t ed25519 -C "[email protected]"
ssh-keygen -t ed25519 -C "[email protected]"
ssh-copy-id amine@your-server-ip
ssh-copy-id amine@your-server-ip
ssh-copy-id amine@your-server-ip
ssh amine@your-server-ip
ssh amine@your-server-ip
ssh amine@your-server-ip
-weight: 600;">sudo vim /etc/ssh/sshd_config
-weight: 600;">sudo vim /etc/ssh/sshd_config
-weight: 600;">sudo vim /etc/ssh/sshd_config
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
ChallengeResponseAuthentication no
UsePAM no
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
ChallengeResponseAuthentication no
UsePAM no
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
ChallengeResponseAuthentication no
UsePAM no
-weight: 600;">sudo -weight: 500;">systemctl reload sshd
-weight: 600;">sudo -weight: 500;">systemctl reload sshd
-weight: 600;">sudo -weight: 500;">systemctl reload sshd
-weight: 600;">sudo -weight: 500;">apt -weight: 500;">install ufw -y
-weight: 600;">sudo ufw default deny incoming
-weight: 600;">sudo ufw default allow outgoing
-weight: 600;">sudo ufw allow OpenSSH
-weight: 600;">sudo ufw -weight: 500;">enable
-weight: 600;">sudo -weight: 500;">apt -weight: 500;">install ufw -y
-weight: 600;">sudo ufw default deny incoming
-weight: 600;">sudo ufw default allow outgoing
-weight: 600;">sudo ufw allow OpenSSH
-weight: 600;">sudo ufw -weight: 500;">enable
-weight: 600;">sudo -weight: 500;">apt -weight: 500;">install ufw -y
-weight: 600;">sudo ufw default deny incoming
-weight: 600;">sudo ufw default allow outgoing
-weight: 600;">sudo ufw allow OpenSSH
-weight: 600;">sudo ufw -weight: 500;">enable
-weight: 600;">sudo ufw -weight: 500;">status verbose
-weight: 600;">sudo ufw -weight: 500;">status verbose
-weight: 600;">sudo ufw -weight: 500;">status verbose
-weight: 600;">sudo ufw allow 80/tcp
-weight: 600;">sudo ufw allow 443/tcp
-weight: 600;">sudo ufw allow 80/tcp
-weight: 600;">sudo ufw allow 443/tcp
-weight: 600;">sudo ufw allow 80/tcp
-weight: 600;">sudo ufw allow 443/tcp
-weight: 600;">sudo -weight: 500;">apt -weight: 500;">install fail2ban -y
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">enable --now fail2ban
-weight: 600;">sudo -weight: 500;">apt -weight: 500;">install fail2ban -y
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">enable --now fail2ban
-weight: 600;">sudo -weight: 500;">apt -weight: 500;">install fail2ban -y
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">enable --now fail2ban
-weight: 600;">sudo fail2ban-client -weight: 500;">status sshd
-weight: 600;">sudo fail2ban-client -weight: 500;">status sshd
-weight: 600;">sudo fail2ban-client -weight: 500;">status sshd
Status for the jail: sshd
|- Filter
| |- Currently failed: 0
| |- Total failed: 0
| `- File list: /var/log/auth.log
`- Actions |- Currently banned: 0 |- Total banned: 0 `- Banned IP list:
Status for the jail: sshd
|- Filter
| |- Currently failed: 0
| |- Total failed: 0
| `- File list: /var/log/auth.log
`- Actions |- Currently banned: 0 |- Total banned: 0 `- Banned IP list:
Status for the jail: sshd
|- Filter
| |- Currently failed: 0
| |- Total failed: 0
| `- File list: /var/log/auth.log
`- Actions |- Currently banned: 0 |- Total banned: 0 `- Banned IP list:
-weight: 600;">sudo vim /etc/fail2ban/jail.local
-weight: 600;">sudo vim /etc/fail2ban/jail.local
-weight: 600;">sudo vim /etc/fail2ban/jail.local
[sshd]
enabled = true
maxretry = 3
findtime = 10m
bantime = 1h
[sshd]
enabled = true
maxretry = 3
findtime = 10m
bantime = 1h
[sshd]
enabled = true
maxretry = 3
findtime = 10m
bantime = 1h
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">restart fail2ban
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">restart fail2ban
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">restart fail2ban
-weight: 600;">sudo -weight: 500;">apt -weight: 500;">install unattended-upgrades -y
-weight: 600;">sudo dpkg-reconfigure --priority=low unattended-upgrades
-weight: 600;">sudo -weight: 500;">apt -weight: 500;">install unattended-upgrades -y
-weight: 600;">sudo dpkg-reconfigure --priority=low unattended-upgrades
-weight: 600;">sudo -weight: 500;">apt -weight: 500;">install unattended-upgrades -y
-weight: 600;">sudo dpkg-reconfigure --priority=low unattended-upgrades
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">status unattended-upgrades
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">status unattended-upgrades
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">status unattended-upgrades
# SSH config — both should say "no"
-weight: 600;">sudo sshd -T | grep -E "permitrootlogin|passwordauthentication" # Firewall — should show only the ports you opened
-weight: 600;">sudo ufw -weight: 500;">status # fail2ban — should show the sshd jail as active
-weight: 600;">sudo fail2ban-client -weight: 500;">status sshd # Unattended upgrades — should be active
-weight: 600;">sudo -weight: 500;">systemctl is-active unattended-upgrades
# SSH config — both should say "no"
-weight: 600;">sudo sshd -T | grep -E "permitrootlogin|passwordauthentication" # Firewall — should show only the ports you opened
-weight: 600;">sudo ufw -weight: 500;">status # fail2ban — should show the sshd jail as active
-weight: 600;">sudo fail2ban-client -weight: 500;">status sshd # Unattended upgrades — should be active
-weight: 600;">sudo -weight: 500;">systemctl is-active unattended-upgrades
# SSH config — both should say "no"
-weight: 600;">sudo sshd -T | grep -E "permitrootlogin|passwordauthentication" # Firewall — should show only the ports you opened
-weight: 600;">sudo ufw -weight: 500;">status # fail2ban — should show the sshd jail as active
-weight: 600;">sudo fail2ban-client -weight: 500;">status sshd # Unattended upgrades — should be active
-weight: 600;">sudo -weight: 500;">systemctl is-active unattended-upgrades
-weight: 600;">sudo ufw delete allow OpenSSH
-weight: 600;">sudo ufw allow 2222/tcp
-weight: 600;">sudo -weight: 500;">systemctl reload sshd
-weight: 600;">sudo ufw delete allow OpenSSH
-weight: 600;">sudo ufw allow 2222/tcp
-weight: 600;">sudo -weight: 500;">systemctl reload sshd
-weight: 600;">sudo ufw delete allow OpenSSH
-weight: 600;">sudo ufw allow 2222/tcp
-weight: 600;">sudo -weight: 500;">systemctl reload sshd
Host my-vps HostName your-server-ip User amine Port 2222 IdentityFile ~/.ssh/id_ed25519
Host my-vps HostName your-server-ip User amine Port 2222 IdentityFile ~/.ssh/id_ed25519
Host my-vps HostName your-server-ip User amine Port 2222 IdentityFile ~/.ssh/id_ed25519 - A fresh VPS running Ubuntu 22.04+ or Debian 11+ (most steps work on any modern distro)
- Root SSH access — ideally a just-provisioned server, before you've done anything else
- An SSH key on your local machine (we'll generate one if you don't have it) - PermitRootLogin no — root cannot SSH in at all
- PasswordAuthentication no — only SSH keys work, no passwords
- PubkeyAuthentication yes — explicitly -weight: 500;">enable SSH keys (usually default but be explicit)
- ChallengeResponseAuthentication no and UsePAM no — close fallback authentication paths - Application-layer security — if you're running a web app, you still need to harden Nginx, your reverse proxy, your CMS, and so on
- Intrusion detection — tools like AIDE or Wazuh for filesystem integrity and behavioral monitoring
- Centralized logging — shipping logs to a separate server so an attacker who lands on the box can't quietly cover their tracks
- Backups — hardening means nothing if you can't restore after an incident - -weight: 500;">apt -weight: 500;">update && -weight: 500;">apt -weight: 500;">upgrade
- Create non-root user with -weight: 600;">sudo
- SSH key auth set up
- Root login + password auth disabled in sshd_config
- UFW firewall enabled, only the ports you need
- fail2ban watching the SSH jail
- Unattended security updates running