Computer Networks

SSH

Authenticated, encrypted remote shells and tunnels. Keys, not passwords, if you can.

Level: beginner

What is it?

Secure Shell (SSH) is a protocol suite for authenticated and encrypted remote command execution, file transfer, and tunneling. It commonly authenticates servers using host keys and clients using passwords, public keys, certificates, or other configured methods.

Why does it matter?

SSH provides a secure administrative channel across untrusted networks. Secure use depends on host identity verification, key hygiene, access control, patching, and minimizing exposed services.

Mental model

The client first establishes an encrypted channel and verifies the server's host identity, then authenticates the user. Encryption without correct host-key verification can protect traffic to an impostor.

How it works

  • SSH host keys let clients detect server identity changes; blindly accepting unknown keys weakens this protection.
  • Public-key authentication lets the client prove possession of a private key without sending that private key to the server.
  • SSH agent forwarding and port forwarding introduce trust and exposure considerations.
  • SCP, SFTP, and remote shell capabilities use SSH in different ways and have distinct semantics.
  • Least privilege, key rotation, restrictive authorized_keys options, and disabling unnecessary account access improve security.

Steps

  • The client connects to the server and negotiates algorithms/keys.
  • It verifies the server host key according to the user's trust configuration.
  • The client authenticates the user with an allowed method.
  • The client opens a shell, command channel, file transfer, or tunnel according to server policy.

Real-world usage

  • Secure remote administration and deployment workflows.
  • SFTP file transfer and local/remote port forwarding.

Common mistakes

  • Disabling host-key checking as a routine workaround.
  • Sharing private keys or leaving them unprotected.
  • Assuming SSH tunnels automatically add application-layer authentication or authorization.

Interview questions

What is the purpose of an SSH host key?

It allows a client to identify the server endpoint and detect unexpected identity changes, helping prevent man-in-the-middle attacks.

Why can agent forwarding be risky?

A remote host may be able to request signatures through the forwarded agent while the session is active, so forwarding increases the trust placed in that host.

Prerequisites

Continue learning

Browse the full computer science library