keepcalculator

06 Numbers and Powers

SSH vs TLS: Which Protocol Fits Your Connection?

Card No. 06·30236 · Updated · Standard formula, shown below

SSH and TLS are both cryptographic protocols that secure data in transit, but they serve different primary purposes: SSH is built for secure remote access and command execution, while TLS is designed to encrypt data between applications (like HTTPS). Choose SSH when you need to manage a server remotely; choose TLS when you need to secure web, email, or API traffic. This article explains how each works, where they overlap, and how to pick the right one for your use case.

Background: Where Each Protocol Came From

SSH (Secure Shell) was created in 1995 by Tatu Ylönen as a replacement for insecure remote login protocols like Telnet and rlogin. Those older protocols sent passwords and data in plaintext, so anyone on the network could sniff them. SSH added strong encryption and authentication, making remote administration safe over untrusted networks. It quickly became the standard for Unix-like systems and is now built into most operating systems.

TLS (Transport Layer Security) evolved from SSL (Secure Sockets Layer), which Netscape developed in the mid-1990s to protect web transactions. SSL 2.0 and 3.0 had serious flaws, so the IETF standardized TLS 1.0 in 1999. Since then, TLS has gone through versions 1.1, 1.2, and 1.3, each adding stronger cipher suites and better handshake security. Today, TLS protects not just web traffic (HTTPS) but also email (SMTP, IMAP, POP), VPNs, VoIP, and countless APIs.

Both protocols use public-key cryptography to establish a shared secret, then switch to symmetric encryption for the bulk data. But they were designed for different jobs: SSH for interactive terminal sessions and secure file transfer, TLS for general-purpose encryption between clients and servers.

How SSH Works: The Essentials

SSH uses a client-server model. The server runs an SSH daemon (sshd) listening on port 22 by default. The client initiates a connection, and the two sides perform a handshake:

  • Key exchange: The client and server agree on a session key using a method like Diffie-Hellman or ECDH. This key is used for symmetric encryption of the session.
  • Server authentication: The client verifies the server’s host key (stored in ~/.ssh/known_hosts) to prevent man-in-the-middle attacks. If the key is new, the client warns the user.
  • User authentication: The user proves their identity via password, public key, or other methods (like keyboard-interactive or certificate-based).

Once authenticated, the client can open multiple channels over the same encrypted connection: a shell for commands, port forwarding, or file transfers with SFTP/SCP. SSH also supports tunneling arbitrary TCP traffic, which is why it’s often used as a poor-man’s VPN.

Key strengths of SSH:

  • Strong authentication options (public key, hardware tokens)
  • Built-in file transfer (SFTP, SCP)
  • Port forwarding and dynamic SOCKS proxy
  • Works well in firewalled environments (port 22 is often open)

How TLS Works: The Essentials

TLS also uses a handshake, but it’s more complex because it must support a wide range of applications. The modern TLS 1.3 handshake is efficient:

  • ClientHello: The client sends supported cipher suites and a random nonce.
  • ServerHello: The server picks a cipher suite and sends its certificate (which contains its public key).
  • Key exchange: Using ephemeral Diffie-Hellman (ECDHE), both sides compute a shared secret without ever transmitting it.
  • Finished: Both sides verify the handshake messages and start encrypted communication.

Critical to TLS is the certificate chain. The server presents a certificate signed by a trusted Certificate Authority (CA). The client validates the signature and the domain name. This is how your browser knows it’s talking to the real google.com and not an impostor.

TLS is used in two main modes:

  • One-way TLS: Only the server is authenticated (most HTTPS).
  • Mutual TLS (mTLS): Both client and server present certificates. Common in enterprise APIs and IoT.

TLS 1.3, standardized in 2018, removed older insecure algorithms (like RSA key exchange and CBC ciphers) and reduced round trips to just one. It’s now the default for most web servers.

Key Differences at a Glance

Aspect SSH TLS
Primary use Remote shell, file transfer, tunneling Encrypting application data (HTTPS, email, APIs)
Default port 22 443 (HTTPS)
Authentication User-based (password, public key) Server certificate (usually), optional client cert
Certificate authority Not required (uses host keys) Required for public trust
Data integrity Yes (MAC) Yes (AEAD ciphers)
Tunneling Native port forwarding Not native, but used in VPNs (e.g., OpenVPN)
Performance Good, but interactive latency matters Optimized for high throughput

Both provide confidentiality, integrity, and authentication. The difference is in who is authenticated and how the protocol is used.

How to Choose: Practical Scenarios

Your choice depends on what you’re trying to accomplish. Here’s a quick guide:

  • Remote server administration: Use SSH. It gives you a secure shell, file transfer, and tunneling in one tool.
  • Securing a website or API: Use TLS (HTTPS). You need a certificate from a CA so browsers trust you.
  • Encrypting a database connection: Many databases (PostgreSQL, MySQL) support both TLS and SSH tunneling. TLS is simpler if the server has a certificate; SSH tunneling works if you only have SSH access.
  • Creating a VPN: Both can be used. OpenVPN uses TLS for the control channel; WireGuard uses its own protocol. SSH tunneling can act as a lightweight VPN for a single port.
  • Automated machine-to-machine communication: TLS with client certificates (mTLS) is common for microservices. SSH keys are also used for automation (e.g., GitHub deployments).

A common misconception is that SSH is only for sysadmins. But it’s also used for secure file transfer (SFTP), Git over SSH, and even as a SOCKS proxy to bypass censorship. TLS, on the other hand, is everywhere: every HTTPS connection uses it.

Common Problems and How to Avoid Them

Both protocols have pitfalls. Here are the ones users run into most:

  • SSH host key mismatch: If you reinstall a server, the host key changes, and clients will warn about a possible man-in-the-middle. Fix: remove the old key from known_hosts and verify the new one out-of-band.
  • Weak SSH passwords: Password-based SSH is vulnerable to brute force. Use key-based authentication and disable password login.
  • Expired TLS certificates: Browsers block sites with expired certs. Automate renewal with tools like Let’s Encrypt’s certbot.
  • Mismatched TLS cipher suites: Old clients may not support modern ciphers. Use a tool like SSL Labs to check compatibility.
  • Port conflicts: SSH on port 22 may be blocked on some networks. You can run SSH on port 443 (often allowed) or use TLS-based tools like stunnel to wrap SSH in TLS.

Security-wise, both protocols are strong if configured correctly. The main risks come from misconfiguration (weak keys, disabled certificate validation) or using outdated versions (SSH 1, TLS 1.0/1.1).

Costs and Performance Considerations

Both protocols are free and open standards. The cost is mostly operational:

  • TLS certificates: Publicly trusted certs cost money if you don’t use a free CA like Let’s Encrypt. Internal CAs require setup and maintenance.
  • SSH key management: Managing keys for many users can be a headache. Use an SSH certificate authority or a tool like HashiCorp Vault.
  • Performance: TLS 1.3 is faster than SSH for bulk transfer because it’s optimized for high throughput. SSH adds latency due to interactive echo, but for file transfer (SFTP) it’s comparable.
  • Hardware acceleration: Modern CPUs have AES-NI, which accelerates both protocols. If you’re using a cloud VM, check if the instance type supports it.

For most applications, the performance difference is negligible. The bigger cost is the time to configure and maintain the right authentication.

Alternatives and When to Use Them

Sometimes neither SSH nor TLS is the best fit. Consider these alternatives:

  • IPsec: Encrypts at the IP layer, used for site-to-site VPNs. It’s more complex but can secure all traffic without per-application changes.
  • WireGuard: A modern VPN protocol that’s simpler and faster than IPsec. It uses its own crypto, not TLS.
  • QUIC: A transport protocol built on UDP that uses TLS 1.3 for encryption. It powers HTTP/3 and reduces connection latency.
  • Kerberos: For internal network authentication, it can be more secure than SSH passwords, but it’s complex to set up.

If you need to encrypt a single connection, SSH tunneling or TLS are both fine. If you need to encrypt all traffic from a host, a VPN (IPsec or WireGuard) is better.

Frequently Asked Questions

Can SSH and TLS be used together?

Yes. A common pattern is to wrap SSH in TLS using tools like stunnel or openssl s_server. This hides SSH traffic on port 443, which can bypass firewalls that block port 22. It’s not standard but works.

Is SSH more secure than TLS?

Neither is inherently more secure. SSH has stronger user authentication options (public keys) but TLS has a robust certificate ecosystem. The security depends on configuration. Both are considered cryptographically sound when using current versions (SSH 2, TLS 1.2+).

Does TLS use SSH?

No. They are separate protocols. However, some applications use SSH to set up a TLS tunnel (e.g., ssh -L to forward a port to an HTTPS server).

Why does SSH use port 22 and TLS use port 443?

Port 22 was assigned by IANA for SSH. Port 443 is the standard for HTTPS, which uses TLS. Neither port is required—you can run SSH on any port and TLS on any port, but these are the defaults for compatibility.

Can I use SSH keys for TLS?

Not directly. SSH keys are in a different format (PEM or OpenSSH) and TLS expects X.509 certificates. You can convert an SSH public key to a certificate, but it’s not a standard practice. Better to use a proper CA for TLS.

What is the difference between SSH and SSL? (Common confusion)

SSL is the predecessor of TLS. SSH and SSL/TLS are entirely different protocols. People often say “SSL� when they mean TLS. SSH is for remote shell; SSL/TLS is for encrypting application data. The confusion arises because both use cryptography and have “S� in the name.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →