SSL vs SSH: what is the difference?

11 min readUpdated

SSL, today TLS, and SSH both encrypt a connection, but they decide differently whether the server is the right one. A TLS client accepts a certificate that leads to an authority it already trusts, so a browser can open a site it has never seen. An SSH client accepts a host key stored on an earlier connection, or one signed by an SSH authority its administrator set up [9] [2]. Both terms belong to the SSL and TLS glossary.

TLS
current version 1.3, specified in RFC 9846 [1]
SSH
version 2.0, specified in RFC 4251 to RFC 4254 [2] [3] [4] [5]
Server proves itself with
TLS: an X.509 certificate; SSH: a host key, or an SSH certificate [1] [2] [6]
Default port
443 for HTTPS, 22 for SSH [11]
Speaks first
TLS: the client, with its ClientHello [1]; SSH: both sides send a version line, and in our test the server sent its line first [16]

At a glance

At a glance
AspectSSL/TLSSSH
Main useHTTPS, mail, DNS over TLS, any program-to-program connectionremote login, commands, port forwarding, file transfer
Server identityX.509 certificate from an authority in the client's trust storehost key stored on first connection, or an SSH host certificate
Client identitynone unless the server asks; optional client certificatebuilt into the protocol: public key, password or host-based
File transferFTPS, FTP over TLSSFTP, and scp on top of it

What they have in common

Both build an encrypted, integrity-protected channel in a similar way. The two sides agree on algorithms and derive shared keys with a Diffie-Hellman exchange; TLS 1.3 can also resume from a pre-shared key. The server then signs the handshake with the private key behind its certificate or host key, which proves it holds that key [1] [4]. From there every message is encrypted and integrity-protected. AES-GCM and ChaCha20-Poly1305 are among the algorithms TLS 1.3 cipher suites use and in the default cipher list of the OpenSSH server [1] [6]. Both are designed against eavesdropping and tampering on the network [1] [4].

SSH does not run over TLS. Its own transport layer protocol, RFC 4253, provides server authentication, confidentiality and integrity [4]. "SSL" itself is retired: RFC 9846 forbids negotiating SSL 2.0 or SSL 3.0 for any reason, and what runs today is TLS [1]. The name survives in everyday use, as on SSL vs TLS.

How they verify the server

TLS relies on certificate authorities. A server presents an X.509 certificate that an authority signed after validating the applicant's control of the domain [8]. The client accepts it when the chain leads to a trust anchor, a root certificate in its trust store [9]. Nothing about the site has to be known in advance.

SSH relies on what the client has seen before. RFC 4251 describes two trust models: a local database that maps each host name to its key, or host keys certified by an authority whose key the client holds [2]. OpenSSH implements the first in known_hosts. On first connection it shows the key's fingerprint and asks; once you accept, the key is stored and checked on every later connection, and a changed key is refused [6]. Accepting an unchecked key, RFC 4251 warns, still protects against passive listening but leaves the connection open to an active man-in-the-middle [2]. The fingerprint to compare against comes from ssh-keygen -l -f run on the server's public host key [6].

SSH certificates and SSHFP

The second model is the SSH certificate. ssh-keygen signs a host key with an SSH authority key, and a client that lists the authority's key on a @cert-authority line in known_hosts accepts the host without a prompt [6] [16]. These are not X.509: OpenSSH calls them "a different, and much simpler, format" [6]. A host key fingerprint can also be published in DNS as an SSHFP record. RFC 4255 allows trusting it only when the record is authenticated with DNSSEC, and OpenSSH checks it only with VerifyHostKeyDNS, off by default [7] [6].

TLS authorities are watched in public as well: certificate transparency logs the certificates they issue so that anyone can notice a suspect one [10]. Some apps go further with certificate pinning, accepting only specific certificates or keys for a server, which is close to how SSH treats a host key it has stored.

How they verify the user

SSL/TLS authenticates the server; the client is authenticated only if the server asks [1]. A website then signs users in with its own login. Mutual TLS adds a client certificate where a system must identify the client too; see mTLS.

SSH has user authentication built in, and the server tells the client which methods it may use [3]. RFC 4252 defines public key, password and host-based methods, and public key is the one every implementation must support [3]. For public key authentication, the OpenSSH server looks for the user's key in ~/.ssh/authorized_keys. Password login is on by default there, PasswordAuthentication yes [6].

What first contact looks like

We ran both side by side: an OpenSSH 9.6p1 server and client, an OpenSSL 3.0.13 test server and curl 8.5.0, with our own keys and a test authority, on one machine [16].

What first contact looks like
What we didWhat came back
Opened the SSH port with nc, sent nothingthe server's version line, SSH-2.0-OpenSSH_9.6p1 Ubuntu-3ubuntu13.20, 43 bytes
Opened the TLS port with nc, sent nothing0 bytes: the server waits for a ClientHello
SSH to a host whose key is not in known_hostsED25519 key fingerprint and Are you sure you want to continue connecting (yes/no/[fingerprint])?; answering no gave Host key verification failed.
SSH with StrictHostKeyChecking accept-newconnected, one line added to known_hosts, the next connection asked nothing
SSH after the server's key was replacedWARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!, exit code 255
SSH to a host certificate, client holding only the authority keyconnected without a prompt: matches the ED25519-CERT host certificate
openssl x509 on that SSH certificateUnable to load certificate
curl to a TLS server whose authority is not in the trust storeexit code 60, unable to get local issuer certificate, the same on the second try
The same with --cacert and the test authorityHTTP 200

Where each is used

  • TLS: HTTPS websites and APIs, mail with implicit TLS on ports 465 and 993, and DNS over TLS on port 853 [13] [11]. The ports by protocol are on port 443.

  • SSH: remote login to servers and network devices, running commands, forwarding TCP ports through the connection, Git over SSH, and copying files [2] [5] [6] [15].

  • SFTP and FTPS are confused because of the names. SFTP is file transfer inside an SSH connection, served by the SSH server's sftp subsystem [6]. FTPS is FTP secured with TLS: RFC 4217 upgrades the FTP control connection, port 21 in the IANA registry, with an AUTH TLS command, and IANA lists port 990 for FTP control over TLS [12] [11]. The current scp also moves data with the SFTP protocol; scp -O falls back to the legacy SCP protocol for servers without SFTP [6].

Which to use

The job decides, not the encryption.

  • Serving a website or an API: TLS. A browser reaches a site through an https URL, which RFC 9110 defines over a TLS connection [14], and the server needs a certificate from an authority in the browser's trust store.

  • Administering a server: SSH with public key login. Once keys work, set PasswordAuthentication no, because the server allows passwords by default [6]. For many servers, host certificates replace the first-connection prompt with one authority key on each client [6].

  • Transferring files: SFTP between systems you control; HTTPS uploads for anything public-facing.

Running both on one server is normal: HTTPS on 443 for visitors, SSH on 22 for the people who maintain it.

FAQ

What is the difference between SSL and SSH?

SSL, now TLS, secures connections between programs such as browsers and websites and verifies servers with certificates from trusted authorities. SSH secures remote logins, commands and file transfers and verifies servers with host keys the client has stored, or with SSH certificates. [1] [2]

Is SSH more secure than SSL?

Neither is more secure in general; both use Diffie-Hellman key exchange and authenticated encryption such as AES-GCM. They differ in how trust is established: TLS relies on certificate authorities, SSH on host keys the client accepts and remembers, or on an SSH authority. [1] [4] [6]

Does SSH use SSL certificates?

No. SSH uses host keys and, optionally, OpenSSH certificates, a different format from X.509. In our test, openssl could not load one. [6] [16]

Does SSH use TLS?

No. SSH has its own transport layer protocol, defined in RFC 4253, and does not run over TLS. [4]

What port does SSH use, and what port does SSL use?

SSH uses port 22 by default. HTTPS uses port 443; other TLS protocols have their own ports, such as 465 and 993 for mail. [11] [13]

Is SFTP the same as FTPS?

No. SFTP is file transfer over SSH. FTPS is FTP over TLS. Both encrypt the transfer, but they are different protocols on different ports. [6] [11] [12]

Can I use SSH instead of HTTPS for a website?

No. An https URL means HTTP over a TLS connection, and the server needs a certificate from an authority the browser trusts. SSH is not part of that path. [14]

What is an SSH public key, and how is it different from the public key in a certificate?

An SSH public key is the shareable half of a key pair, and SSH uses it in two roles. A server's host key is used during key exchange to verify the server to the client. A user's public key identifies the user: possession of the private key is the authentication, and the server accepts a signature only from a key that is a valid authenticator for that user. A raw SSH public key carries no issuer. The ssh-rsa format is only the algorithm name, an exponent and a modulus, and ECDSA and Ed25519 keys have formats of their own. Trust therefore comes from outside the key: the client holds a local database that maps each host name to its key, or the key is certified by an authority the client trusts. In an X.509 certificate the public key sits beside the subject and the issuer, and the issuer's signature covers the whole structure.

Sources

  1. RFC 9846, TLS 1.3: §1, §2, §4.2.2, §4.5.1.2, §4.5.2, Appendix B.4, Appendix E.5.

  2. RFC 4251, SSH protocol architecture: §1, §4.1.

  3. RFC 4252, SSH authentication protocol: §1, §4, §7, §8, §9.

  4. RFC 4253, SSH transport layer protocol: abstract, §4.1, §4.2, §8.

  5. RFC 4254, SSH connection protocol: §6, §7.

  6. OpenSSH manual pages: ssh(1), ssh_config(5), sshd(8), sshd_config(5), ssh-keygen(1), scp(1), sftp(1).

  7. RFC 4255, SSHFP: using DNS to publish SSH key fingerprints, §2.4.

  8. CA/Browser Forum Baseline Requirements, §3.2.2.4, validation of domain authorization or control.

  9. RFC 5280, X.509 profile: §6.1, path validation.

  10. RFC 9162, Certificate Transparency version 2.0: abstract.

  11. IANA Service Name and Transport Protocol Port Number Registry: ssh, https, ftp, ftps, submissions, imaps, domain-s.

  12. RFC 4217, Securing FTP with TLS.

  13. RFC 8314, implicit TLS for mail submission and access; RFC 7858, DNS over TLS, §3.1.

  14. RFC 9110, HTTP semantics: §4.2.2, the https URI scheme.

  15. Pro Git, Git on the Server: The Protocols.

  16. Test on this page: OpenSSH 9.6p1 client and server, OpenSSL 3.0.13 s_server, curl 8.5.0; own keys, own SSH and TLS test authorities, localhost.

  17. RFC 4253, SSH transport layer protocol: §6.6, public key algorithms (ssh-rsa), in addition to item 4.

  18. RFC 5280, X.509 profile: §4.1, basic certificate fields, in addition to item 9.

  19. RFC 5656, elliptic curve algorithms for SSH: the ECDSA public key format.

  20. RFC 8709, Ed25519 and Ed448 public key algorithms for SSH: the Ed25519 public key format.