How Does SSH Work?

Listen to this Post

Featured Image
SSH (Secure Shell) is a network protocol used to securely connect to remote machines over an unsecured network. It ensures confidentiality, integrity, and authentication for remote access, file transfers, and command execution, protecting data from eavesdropping and tampering.

Here’s a breakdown of the main events that occur during an SSH connection:

1) Key Exchange

SSH begins with a key exchange process, typically using the Diffie-Hellman algorithm. The client and server exchange public components to derive a shared secret, creating a secure session key for encrypted communication without transmitting sensitive private keys.

2) Server Verification

The client validates the server’s identity by checking its public key against a locally stored `known_hosts` file. This prevents man-in-the-middle (MITM) attacks, ensuring the connection is established only with a trusted server.

3) Session Key & Encryption Setup

After establishing the shared secret, SSH derives a symmetric session key. This key encrypts all subsequent communication, providing both confidentiality (data remains private) and integrity (modifications are detected).

4) Client Authentication

The client proves its identity through authentication methods, such as public key authentication. The client signs a server-provided challenge with its private key, and the server verifies it using the client’s public key.

You Should Know:

SSH Commands & Practical Usage

Basic SSH Connection

ssh username@remote_host 

Using a Specific Port

ssh -p 2222 username@remote_host 

Generating SSH Keys

ssh-keygen -t rsa -b 4096 

Copying Public Key to Remote Server

ssh-copy-id username@remote_host 

SSH Config File (~/.ssh/config)

Host myserver 
HostName server.example.com 
User myuser 
Port 2222 
IdentityFile ~/.ssh/my_private_key 

Checking SSH Fingerprint (Server Verification)

ssh-keygen -lf /etc/ssh/ssh_host_rsa_key.pub 

Forcing SSH to Use a Specific Key

ssh -i ~/.ssh/custom_key username@remote_host 

Tunneling with SSH (Port Forwarding)

ssh -L 8080:localhost:80 username@remote_host  Local forwarding 
ssh -R 9000:localhost:3000 username@remote_host  Remote forwarding 

Disabling Password Authentication (Hardening SSH)

Edit `/etc/ssh/sshd_config`:

PasswordAuthentication no 
PermitRootLogin no 

Then restart SSH:

sudo systemctl restart sshd 

Debugging SSH Connection Issues

ssh -vvv username@remote_host 

What Undercode Say:

SSH is a fundamental tool for secure remote administration, but many users only scratch the surface of its capabilities. Beyond basic logins, SSH enables:
– Secure file transfers (scp, sftp)
– Tunneling (bypassing firewalls securely)
– Agent forwarding (managing keys securely)
– Automated scripts (using `sshpass` or `expect` carefully)

For advanced hardening:

  • Use ed25519 keys (ssh-keygen -t ed25519)
  • Enforce 2FA via SSH (Google Authenticator PAM module)
  • Rotate keys frequently and use certificate-based auth

Expected Output:

A secure, encrypted, and authenticated remote session with full control over remote systems while preventing eavesdropping and MITM attacks.

Further Reading:

References:

Reported By: Nikkisiapno How – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅

Join Our Cyber World:

💬 Whatsapp | 💬 Telegram