Encryption & Secure Communication

SSH (Secure Shell)

About 5 min read

What Is SSH

SSH (Secure Shell) is a cryptographic network protocol for securely accessing remote computers over an unsecured network. It encrypts the communication so that passwords, commands, and data cannot be read by third parties along the way.

Before SSH, protocols like Telnet and rlogin transmitted data in plaintext, leaving them vulnerable to eavesdropping. According to the OpenSSH project history, OpenSSH derives from the original free ssh 1.2.12 release by Tatu Ylönen, and OpenBSD developers began the work in 1999. The SSH protocol was standardized as RFC 4251 to 4254 in January 2006.

Today, SSH is used for server administration, cloud infrastructure management, Git repository access, automated deployment pipelines, and more. The default port number is 22.

Public Key Authentication

Public key authentication is the method that the SSH authentication specification (RFC 4252) makes REQUIRED to implement (password authentication is OPTIONAL); it uses a mathematically linked pair of keys (public and private) instead of passwords.

  1. Key pair generation: Run ssh-keygen on the client to create a public/private key pair. The private key stays on the client and must never be shared.
  2. Public key registration: Add the public key to the server's ~/.ssh/authorized_keys file.
  3. Authentication process: The client signs data that includes the session identifier (the exchange hash from key exchange) with the private key, and the server verifies the signature using the registered public key (RFC 4252). The private key never travels over the network.
Password Authentication
Easy to set up but vulnerable to brute-force attacks. The password traverses the network (encrypted, but decrypted on the server side).
Public Key Authentication
The private key never leaves the client, so intercepting the traffic does not reveal it. Password-guessing brute-force attacks do not apply. Adding a passphrase means a stolen key file cannot be used right away.

As of October 2026, the ssh-keygen manual (OpenBSD) gives Ed25519 as the default key type and 3072 bits as the default RSA key size, noting that 3072 bits is generally considered sufficient. RFC 8709 states that standard implementations of SSH SHOULD implement the Ed25519 and Ed448 signature algorithms. DSA was disabled by default in 2015, and OpenSSH 10.0 (April 2025) removed support for it. ECDSA (nistp256) is also available.

Port Forwarding

SSH port forwarding (tunneling) securely routes other protocols' traffic through an encrypted SSH connection.

  • Local forwarding: Forwards connections to a local port through the SSH tunnel to a remote destination. Example: ssh -L 3306:db-server:3306 bastion connects to a database via a bastion host. Useful for reaching services behind a firewall.
  • Remote forwarding: Forwards connections to a remote port back through the tunnel to the client side. Used to expose services behind NAT to the outside.
  • Dynamic forwarding: Uses the SSH connection as a SOCKS proxy. ssh -D 1080 server routes browser traffic through the tunnel when configured as a proxy, so the segment up to the SSH server is encrypted.

Port forwarding is used when you need secure access to specific services without setting up a full VPN. Multi-hop SSH connections through bastion hosts can be configured using the ProxyJump directive in ~/.ssh/config.

SCP and SFTP File Transfers

SCP (Secure Copy Protocol)
Simple one-command file copying: scp file.txt user@server:/path/. Cannot resume interrupted transfers. Since OpenSSH 9.0 (April 2022), scp uses the SFTP protocol by default.
SFTP (SSH File Transfer Protocol)
Interactive file operations including directory listing, deletion, renaming, and resumable transfers. GUI clients such as WinSCP, FileZilla, and Cyberduck are available. Not to be confused with FTPS (FTP over TLS).

Legacy FTP transmits passwords and file contents in plaintext. SFTP sends them inside the encrypted SSH connection.

SSH Security Best Practices

  • Disable password authentication: Set PasswordAuthentication no in /etc/ssh/sshd_config to allow only public key authentication. The sshd_config default is yes; with password authentication disabled, password-guessing brute-force attacks no longer work.
  • Disable root login: Set PermitRootLogin no (the default is prohibit-password, which refuses only password-based root login) and use sudo for privilege escalation after logging in as a regular user.
  • Change the default port: Moving from port 22 to a non-standard port is done to reduce automated connection attempts, though it is not a substitute for proper authentication controls.
  • Restrict source IPs: Use firewall rules or cloud security groups to limit SSH access to known IP addresses.
  • Deploy Fail2ban: According to its official repository, a daemon that bans hosts causing multiple authentication errors.
  • Rotate keys regularly: Periodically update SSH keys and promptly remove keys of departed employees from authorized_keys.

Common Misconceptions

SSH is only for system administrators
Developers use SSH for Git access (git@github.com:...), CI/CD pipelines use it for deployment, and data scientists use it to connect to remote GPU servers. SSH is also used in work other than system administration.
Changing the SSH port makes you secure
A changed port can still be found by a port scan, so it does not replace authentication controls. It is used together with disabling password authentication, enforcing public key auth, and restricting source IPs.
SSH keys last forever once created
OpenSSH's ssh-keygen can set a validity interval (-V) when signing certificates. Periodic key rotation addresses risks such as forgotten removal of departed employees' keys, potential private key leaks, and algorithm obsolescence.
Share

Related Terms

Related Articles