DEV Community

dpm_bush
dpm_bush

Posted on Originally published at sshflow.com

SSH vs TLS: Choose the Right Protocol for the Connection

SSH and TLS both encrypt network traffic, but they solve different problems. SSH is commonly used to log in to and administer remote systems. TLS protects application connections, such as a browser connecting to a website over HTTPS.

They aren't competing versions of the same tool. In some setups, they can even protect different parts of one connection.

Start with the job you're doing

Use SSH when you need a remote shell, want to run commands on a server, transfer files through SFTP, or forward a connection through an SSH host.

Use TLS when an application needs a protected connection to another application or service. HTTPS is the familiar example, but TLS is also used for other kinds of application traffic.

ssh user@server.example.com
Enter fullscreen mode Exit fullscreen mode

That command starts an SSH connection to a remote server. By contrast, opening https://example.com in a browser starts an application connection protected by TLS.

SSH can forward application traffic, but that doesn't turn the application protocol into SSH. And TLS by itself doesn't provide a remote shell.

The trust checks are different

Encryption is only part of a secure connection. Both protocols also need a way to check identity, but their trust models differ.

SSH: verify the host, then authenticate the user

SSH clients commonly use a server's host key to verify which server they're connecting to. Host keys may be recorded in known_hosts; on a first connection, you may be asked to verify a fingerprint. If a known host's key changes, SSH can warn you. A rebuild or key rotation might explain the change, but you should verify it rather than ignoring the warning.

User authentication is a separate check. Depending on server configuration, the user might authenticate with a public key, a password, or another accepted method. Having a private key for user authentication doesn't, by itself, verify the server's identity.

TLS: validate the certificate for the requested name

For HTTPS, the server presents an X.509 certificate. The client checks that it chains to a trusted certificate authority and is valid for the hostname it intended to reach.

Ordinary HTTPS usually authenticates the server to the client. It doesn't automatically identify every visitor to the server; websites commonly handle user login separately. For some service-to-service connections, mutual TLS (mTLS) can also authenticate the client with a certificate.

SSH host keys, SSH certificates, and TLS X.509 certificates belong to different trust systems. The shared word “certificate” doesn't make them interchangeable.

Ports are clues, not definitions

SSH commonly uses TCP port 22, though a server can be configured to use another port. HTTPS commonly uses TCP port 443; other TLS-protected applications use their own ports.

For example, to connect to an SSH server configured on port 2222:

ssh -p 2222 user@server.example.com
Enter fullscreen mode Exit fullscreen mode

A port number alone doesn't prove which protocol is running there. Services can use custom ports, and proxies or forwarding can affect how they are exposed.

One workflow can use both

Suppose an internal web service is reachable from an SSH server but not directly from your laptop. You can forward a local port to that service's HTTPS port:

ssh -L 8443:internal.example:443 user@jump-host.example.com
Enter fullscreen mode Exit fullscreen mode

While that SSH connection is open, a local application can connect through port 8443. SSH carries the forwarded connection to internal.example:443; TLS can still protect the application's connection to the service.

The two layers have separate responsibilities: SSH provides the tunnel to the jump host, while TLS handles the application connection and its server identity checks. Configure hostname validation for the service's identity as appropriate. Don't disable certificate verification simply because the traffic travels inside an SSH tunnel.

Quick decision guide

Need Typical choice What it provides
Log in to a server or run remote commands SSH A remote session with configured user authentication
Secure a website or web API TLS, usually HTTPS Protection for application traffic and server identity validation
Transfer files through an SSH account SFTP over SSH File transfer through the SSH service
Secure FTP-based traffic with TLS FTPS FTP protected with TLS; a different setup from SFTP
Reach a private service through a host you can SSH into SSH forwarding, possibly with TLS A path to the service; TLS can still secure the application connection

SFTP and FTPS are distinct protocols, despite their similar names. SFTP is an SSH subsystem; FTPS is FTP secured with TLS.

Is one more secure?

There's no universal winner. Compare configurations that do the same job and address the same threat model. An SSH setup with weak host-key verification or poor access controls can be risky. A TLS setup with incorrect certificate validation or outdated software can be risky too.

The practical question is whether the protocol fits the task and whether its identity checks, credentials, and software are handled correctly. SSH is the usual fit for remote administration; TLS is the usual fit for securing application connections.

One naming note: SSL was the predecessor to TLS and is obsolete. People still say “SSL” informally, but modern secure HTTPS connections use TLS.

I originally published a more detailed version of this guide on the SSHFlow blog.

I'm also building SSHFlow — an SSH client where every server gets its own workspace for terminals, SFTP, code, and databases.

Top comments (0)