PassioniInformaticaLinux

Guida: SSH sicuro — chiavi, hardening e tunneling

25/02/2026

Configurazione avanzata di SSH su server Linux

Come blindare SSH: autenticazione con chiavi, disabilitare password, tunneling e port forwarding.

1. Generare chiavi SSH (sul client)

ssh-keygen -t ed25519 -C "armando@workstation"
# Salva in ~/.ssh/id_ed25519

2. Copiare la chiave sul server

ssh-copy-id -i ~/.ssh/id_ed25519.pub root@192.168.1.100
# Oppure manualmente:
cat ~/.ssh/id_ed25519.pub | ssh root@192.168.1.100 "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

3. Hardening sshd_config

Modifica /etc/ssh/sshd_config:

# Disabilita login con password
PasswordAuthentication no
PubkeyAuthentication yes

# Disabilita login root (usa sudo)
PermitRootLogin prohibit-password

# Solo protocollo 2
Protocol 2

# Timeout sessioni inattive
ClientAliveInterval 300
ClientAliveCountMax 2

# Limita utenti
AllowUsers armando

# Porta custom (opzionale)
Port 2222
systemctl restart sshd

4. SSH Tunnel (port forwarding locale)

# Accedi a servizio remoto (es. MySQL su server) via porta locale
ssh -L 3307:localhost:3306 armando@server
# Ora collegati a localhost:3307 per raggiungere MySQL remoto

5. SSH Jump Host (bastion)

# Raggiungi un server interno tramite un bastion host
ssh -J armando@bastion armando@server-interno

# Oppure in ~/.ssh/config:
Host server-interno
    HostName 192.168.1.100
    User armando
    ProxyJump bastion

6. SSH Config per gestire molti server

# ~/.ssh/config
Host proxmox
    HostName 192.168.1.81
    User root
    IdentityFile ~/.ssh/id_ed25519

Host web-server
    HostName 192.168.1.92
    User root
    ProxyJump proxmox

Risultato: SSH blindato con chiavi, hardening completo, tunneling e gestione multi-server.

← Guida: Firewall UFW — regole essenziali per ser... Guida: Backup automatici con rsync + cron →
← Torna all'elenco