0Pricing
Linux Networking & TCP/IP for Developers · Lezione

Hardening SSH e autenticazione basata su chiavi

Metta in sicurezza il servizio più esposto dei server Linux: configuri SSH per l’accesso esclusivamente tramite chiave, disabiliti le impostazioni predefinite rischiose e riduca la superficie di attacco.

Hardening SSH e autenticazione basata su chiavi è una lezione Linux Networking & TCP/IP for Developers gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Linux Networking & TCP/IP for Developers, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Linux Networking & TCP/IP for Developers include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

Why Harden SSH

SSH is the primary remote-administration channel and a constant target of automated brute-force attacks.

Hardening SSH dramatically reduces the risk of unauthorized access with a handful of configuration changes in /etc/ssh/sshd_config.

Generating a Strong Key Pair

Prefer modern Ed25519 keys over older RSA. Generate a pair with a passphrase for defense in depth.

ssh-keygen -t ed25519 -C 'admin@server'

Installing the Public Key

Copy the public key to the server's ~/.ssh/authorized_keys. The helper ssh-copy-id automates this safely.

ssh-copy-id -i ~/.ssh/id_ed25519.pub admin@server

Disabling Password Authentication

Once key login works, turn off passwords entirely so brute-force attacks cannot succeed.

In sshd_config:

  • PasswordAuthentication no
  • ChallengeResponseAuthentication no
  • UsePAM yes
PasswordAuthentication no

Disabling Root Login

Never allow direct root SSH login. Log in as a normal user and escalate with sudo.

PermitRootLogin no

Restricting Users

Limit who may connect with AllowUsers or AllowGroups. Anyone not listed is rejected outright.

AllowUsers admin deploy

Changing the Default Port

Moving off port 22 will not stop a determined attacker but cuts noisy automated scans considerably.

Remember to update your firewall rules to match.

Port 2222

Limiting Authentication Attempts

Tighten the connection handshake to frustrate brute-force tools.

  • MaxAuthTries 3
  • LoginGraceTime 20
  • MaxStartups 10:30:60
MaxAuthTries 3

Adding Fail2ban

fail2ban watches auth logs and temporarily bans IPs after repeated failures, blocking persistent attackers automatically.

sudo apt install fail2ban
sudo systemctl enable --now fail2ban

Testing Before Disconnecting

Always validate config and keep an existing session open before restarting sshd, so a mistake does not lock you out.

sudo sshd -t && sudo systemctl restart ssh

Verifying the Hardened Config

Confirm the effective settings the daemon will use with sshd -T, which prints the resolved configuration.

sudo sshd -T | grep -E 'permitrootlogin|passwordauthentication'

Quick Check

Test your SSH hardening knowledge.

Recap

You have hardened the most exposed Linux service:

  • Ed25519 key pairs with passphrases
  • PasswordAuthentication no and PermitRootLogin no
  • User restrictions and tightened auth limits
  • fail2ban for automatic banning
  • Always sshd -t and verify before disconnecting

This complements your firewall, VPN, and IDS lessons for layered defense.

Domande Frequenti

La lezione «Hardening SSH e autenticazione basata su chiavi» è gratuita?

Sì — il testo completo di «Hardening SSH e autenticazione basata su chiavi» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Linux Networking & TCP/IP for Developers, passa a CoddyKit PRO. Il corso Linux Networking & TCP/IP for Developers include 4 lezioni in totale.

Cosa imparerò in «Hardening SSH e autenticazione basata su chiavi»?

Metta in sicurezza il servizio più esposto dei server Linux: configuri SSH per l’accesso esclusivamente tramite chiave, disabiliti le impostazioni predefinite rischiose e riduca la superficie di atta… Eserciti Linux Networking & TCP/IP for Developers con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare Linux Networking & TCP/IP for Developers?

Non è richiesta alcuna esperienza precedente. Linux Networking & TCP/IP for Developers su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.

Quanto tempo richiede la lezione «Hardening SSH e autenticazione basata su chiavi»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione Linux Networking & TCP/IP for Developers?

Sì. Ogni lezione Linux Networking & TCP/IP for Developers include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Regole avanzate del firewall (nftables)
  2. Concetti e configurazione delle VPN
  3. Rilevamento delle intrusioni di rete (IDS)
  4. Hardening SSH e autenticazione basata su chiavi
← Torna a Linux Networking & TCP/IP for Developers