<< back to Guides

๐Ÿ›ก๏ธ Deep Dive into SSH (Secure Shell)

SSH (Secure Shell) is a cryptographic network protocol that allows secure communication over an unsecured network. It's widely used by system administrators, developers, and DevOps/SRE teams for accessing and managing remote servers.


๐Ÿ”‘ What Is SSH?

SSH provides a secure channel over an unsecured network using a client-server architecture.

It's most commonly used for:


๐Ÿ” How SSH Works

SSH uses asymmetric encryption, symmetric encryption, and hashing to secure connections.

Key Components:

  1. Key Exchange: Uses algorithms like Diffie-Hellman to negotiate a shared secret between client and server.
  2. Authentication:
    • Password-based (less secure)
    • Key-based (more secure) using id_rsa and id_rsa.pub
  3. Encryption:
    • Once a session is established, a symmetric key encrypts data.
  4. Integrity:
    • Uses MACs (Message Authentication Codes) to ensure message integrity.

๐Ÿงฐ SSH Client Tools

Tool Usage
ssh Connect to remote machines
scp Copy files between local and remote systems
sftp Secure FTP-like file transfer
ssh-agent Stores your decrypted private keys
ssh-add Adds keys to the agent
ssh-keygen Generate public-private key pairs

๐Ÿ”ง SSH Configuration

~/.ssh/config

Host dev
    HostName 192.168.1.10
    User ubuntu
    Port 22
    IdentityFile ~/.ssh/id_rsa

Allows easy connection:

ssh dev

/etc/ssh/sshd_config (on server)

Key settings:


๐Ÿ” SSH Authentication Methods

๐Ÿ”‘ Public Key Authentication

๐Ÿ”’ Password Authentication


๐Ÿงฑ SSH Port Forwarding (Tunneling)

  1. Local Port Forwarding

    • Access a remote service locally.
    • Example: Forward remote DB to local port
    ssh -L 3307:localhost:3306 user@remote
    
  2. Remote Port Forwarding

    • Let a remote machine access a service on your local machine.
    ssh -R 9090:localhost:3000 user@remote
    
  3. Dynamic Port Forwarding

    • Acts like a SOCKS proxy.
    ssh -D 1080 user@remote
    

๐Ÿงช Hardening SSH


๐Ÿš€ Common Use Cases


๐Ÿ“ฆ Related Tools & Ecosystem

Tool Description
OpenSSH The most widely used SSH implementation
PuTTY Windows-based SSH client
Mosh Mobile-friendly SSH client with UDP
SSHFS Mount remote FS over SSH
tmux / screen Session persistence over SSH

๐Ÿ“š Learning Resources


<< back to Guides