1 10-Tabella-HTTPS-vs-SSH
Emanuele edited this page 2025-12-25 13:28:16 +01:00
This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

10 - Tabella HTTPS vs SSH

Comparazione completa tra i due protocolli per accedere a repository Git remoti.


Comparazione Generale

Caratteristica HTTPS SSH
Porta 443 (standard web) 22 / 2222 (custom)
Autenticazione Username + Token Chiavi pubbliche/private
Firewall Passa sempre ⚠️ Spesso bloccata
Setup Semplice (token) 🔧 Medio (genera chiavi)
Sicurezza TLS/SSL crittografato Crittografia SSH
Superficie attacco Minore (1 porta) ⚠️ Maggiore (2+ porte)
Gestione certificati Automatica (Let's Encrypt) N/A
Performance ≈ Equivalente ≈ Equivalente
CI/CD Semplice 🔧 Richiede key management
Multi-account 🔧 Token separati Chiavi separate

Sintassi URL

HTTPS

https://git.emanuelegori.uno/username/repository.git

SSH

git@git.emanuelegori.uno:username/repository.git
# oppure esplicito
ssh://git@git.emanuelegori.uno:2222/username/repository.git

Tabella Comandi Comparativa

Clone

Operazione HTTPS SSH
Clone base git clone https://git.emanuelegori.uno/user/repo.git git clone git@git.emanuelegori.uno:user/repo.git
Clone con porta custom N/A (sempre 443) git clone ssh://git@git.emanuelegori.uno:2222/user/repo.git
Autenticazione Username + Token (richiesto) Chiave SSH (automatica se configurata)

Remote

Operazione HTTPS SSH
Aggiungere remote git remote add origin https://git.emanuelegori.uno/user/repo.git git remote add origin git@git.emanuelegori.uno:user/repo.git
Cambiare URL git remote set-url origin https://git.emanuelegori.uno/user/repo.git git remote set-url origin git@git.emanuelegori.uno:user/repo.git
Verificare URL git remote -v git remote -v

Push

Operazione HTTPS SSH
Push git push origin main git push origin main
Autenticazione Token richiesto (o salvato) Chiave SSH automatica
Primo push git push -u origin main (chiede credenziali) git push -u origin main (automatico)

Pull

Operazione HTTPS SSH
Pull git pull origin main git pull origin main
Autenticazione Token (o salvato) Chiave SSH automatica

Fetch

Operazione HTTPS SSH
Fetch git fetch origin git fetch origin
Autenticazione Token per repo privati Chiave SSH

Autenticazione - Dettaglio

HTTPS

Setup iniziale:

# 1. Genera token su Forgejo (Settings → Applications)
# 2. Copia token (lo vedi solo una volta!)

# 3. Al primo clone/push
git clone https://git.emanuelegori.uno/user/repo.git
Username: username
Password: [INCOLLA TOKEN]

# 4. Salva credenziali (opzionale)
git config --global credential.helper store

File credentials:

~/.git-credentials
https://username:TOKEN@git.emanuelegori.uno

SSH

Setup iniziale:

# 1. Genera chiave SSH
ssh-keygen -t ed25519 -C "email@esempio.com"
# Salva in: ~/.ssh/id_ed25519

# 2. Copia chiave pubblica
cat ~/.ssh/id_ed25519.pub

# 3. Aggiungi su Forgejo (Settings → SSH Keys)

# 4. Test connessione
ssh -T git@git.emanuelegori.uno -p 2222

File config SSH (~/.ssh/config):

Host git.emanuelegori.uno
    HostName git.emanuelegori.uno
    User git
    Port 2222
    IdentityFile ~/.ssh/id_ed25519

Cambio Protocollo

Da HTTPS a SSH

# 1. Verifica URL corrente
git remote -v
# origin  https://git.emanuelegori.uno/user/repo.git (fetch)
# origin  https://git.emanuelegori.uno/user/repo.git (push)

# 2. Cambia a SSH
git remote set-url origin git@git.emanuelegori.uno:user/repo.git

# 3. Verifica
git remote -v
# origin  git@git.emanuelegori.uno:user/repo.git (fetch)
# origin  git@git.emanuelegori.uno:user/repo.git (push)

# 4. Test
git fetch origin

Da SSH a HTTPS

# 1. Cambia a HTTPS
git remote set-url origin https://git.emanuelegori.uno/user/repo.git

# 2. Verifica
git remote -v

# 3. Test (chiederà credenziali)
git fetch origin
Username: ...
Password: [TOKEN]

Pro e Contro

HTTPS

PRO:

  • Setup veloce (solo token)
  • Funziona ovunque (WiFi pubblici, aziende, hotel)
  • Una sola porta (443) già aperta ovunque
  • Gestione certificati automatica (Let's Encrypt)
  • Meno superficie d'attacco (porta SSH chiusa)
  • Ideale per CI/CD (token scadibili)
  • Facile rotazione credenziali (rigenera token)

CONTRO:

  • ⚠️ Token da gestire/salvare
  • ⚠️ Credenziali in chiaro se usi credential.helper store
  • ⚠️ Deve inserire password/token se non salvato

SSH

PRO:

  • Autenticazione automatica (no password)
  • Più comodo per uso quotidiano
  • Chiavi separate per account multipli
  • Standard de-facto per sviluppatori

CONTRO:

  • ⚠️ Setup più complesso (genera chiavi, configura)
  • ⚠️ Porta SSH spesso bloccata (firewall aziendali)
  • ⚠️ Porta SSH esposta = target per attacchi
  • ⚠️ Gestione chiavi SSH su più macchine
  • ⚠️ Problemi se porta 22 non disponibile

Quando Usare Cosa

Usa HTTPS quando:

  • 🏢 Ambiente aziendale - Firewall stringenti
  • 🌍 Lavoro da location diverse - WiFi pubblici, hotel
  • 🔒 Sicurezza prioritaria - Meno porte esposte
  • 🤖 CI/CD - Token scadibili, facile rotazione
  • Setup rapido - Nuova macchina, temporanea
  • 🏠 Server personale - VPS con single-user

Usa SSH quando:

  • 👥 Team grande - Workflow consolidato SSH
  • 💻 Workstation fissa - Sempre stesso ambiente
  • 🔄 Push/pull frequenti - No password da digitare
  • 🔀 Multi-account - Chiavi separate per account diversi
  • 🏢 Organizzazione - Infrastruttura SSH esistente

Caso d'Uso: Server Personale (VPS)

Per un VPS personale con Forgejo (come git.emanuelegori.uno):

Raccomandazione: HTTPS 🏆

Perché:

  1. Sicurezza: Porta SSH chiusa = meno attacchi
  2. Semplicità: Un protocollo, una porta (443)
  3. Affidabilità: NGINX Proxy Manager gestisce tutto
  4. Flessibilità: Funziona da qualsiasi network
  5. Manutenzione: Meno servizi esposti = meno problemi

Configurazione ideale:

# VPS/Server
- Porta 443: HTTPS (NPM → Forgejo, WordPress, ecc.)
- Porta 22: SSH server (solo per admin)
- Porta 2222 Forgejo: CHIUSA

# Client
- Git via HTTPS
- SSH solo per admin server

Sicurezza - Confronto

HTTPS

Protezioni:

  • TLS 1.2+ encryption
  • Certificate pinning (HSTS)
  • Let's Encrypt auto-renewal
  • Token revocabili

Rischi:

  • Token in plaintext se usi credential.helper store
  • Man-in-the-middle se certificato non verificato

Mitigazioni:

# Verifica certificato sempre
git config --global http.sslVerify true

# Usa credential helper sicuro (libsecret/pass)
git config --global credential.helper libsecret

SSH

Protezioni:

  • Crittografia forte (ed25519)
  • Autenticazione pubkey
  • No password in chiaro

Rischi:

  • Porta SSH scansionata da bot
  • Brute force su porta 22
  • Key theft se macchina compromessa

Mitigazioni:

# Porta custom (non 22)
Port 2222

# Disable password auth
PasswordAuthentication no

# Key-based only
PubkeyAuthentication yes

Performance

Metrica HTTPS SSH
Velocità clone ≈ Equivalente ≈ Equivalente
Latenza ~5-10ms extra (TLS handshake) ~5-10ms (SSH handshake)
Throughput Alto Alto
Compression Supportato Supportato

Conclusione: Performance praticamente identica. La scelta non dovrebbe basarsi su velocità.


🔗 Collegamenti


📝 Quick Reference

# HTTPS
git clone https://git.emanuelegori.uno/user/repo.git
git remote add origin https://git.emanuelegori.uno/user/repo.git
# Autenticazione: username + token

# SSH
git clone git@git.emanuelegori.uno:user/repo.git
git remote add origin git@git.emanuelegori.uno:user/repo.git
# Autenticazione: chiave SSH

# Cambio protocollo
git remote set-url origin <nuova-url>