Sécuriser la connexion SSH de votre serveur
Changer le port par défaut de l’accès SSH de votre serveur
- Ouvrir le fichier de config
nano /etc/ssh/sshd_config
-
Modifier le port en remplaçant
#Port 22
parPort 4444
par exemple -
Désactiver au passage l’authentification par mot de passe :
PasswordAuthentication no
-
Redémarrer le serveur
reboot
- Vérifier le changement
ss -tlnp | grep ssh
Vous devriez obtenir un truc de ce style :
LISTEN 0 4096 *:4444 *:* users:(("sshd",pid=1614,fd=3),("systemd",pid=1,fd=97))
Restreindre l’accès SSH de votre serveur à vos adresses IP
Avec Hetzner Cloud Firewall
Voici quelques règles à appliquer sur le Firewall d’Hetzner dont celle sur le service SSH.
- INBOUND
Service | Source IPv4 | Source IPv6 | Protocole | Port |
---|---|---|---|---|
HTTP | any | any | TCP | 80 |
HTTPS | any | any | TCP | 443 |
PING | any | any | ICMP | – |
SSH | yourIP | – | TCP | 4444 |
- OUTBOUND
Service | Source IPv4 | Source IPv6 | Protocole | Port |
---|---|---|---|---|
All TCP | any | any | TCP | 1 - 65535 |
DNS | any | any | UDP | 53 |
NTP | any | any | UDP | 123 |
PING | any | any | ICMP | – |
Avec UFW
Ou vous pouvez utiliser UFW (Uncomplicated Firewall) :
- INBOUND
sudo ufw allow in proto tcp from any to any port 80
sudo ufw allow in proto tcp from any to any port 443
sudo ufw allow in proto icmp
sudo ufw allow in proto tcp from YOUR.IP.ADDR.ESS to any port 4444
- OUTBOUND
sudo ufw allow out proto tcp from any to any port 1:65535
sudo ufw allow out proto udp from any to any port 53
sudo ufw allow out proto udp from any to any port 123
sudo ufw allow out proto icmp
- Activer le Firewall
sudo ufw enable
- Vérifier les règles
sudo ufw status verbose