SSH and TLS both give you an encrypted, authenticated channel, but they trust in opposite ways, and most of the operational risk in each comes from that trust model rather than from the cryptography. SSH was built for administrators reaching hosts, with host keys remembered on first use and user keys placed in files on each server. TLS was built for clients reaching services they have never met, with servers proving identity through X.509 certificates issued by certificate authorities. This guide compares the two for architects, platform engineers and identity teams deciding which protocol belongs where: trust on first use versus PKI, how each end is authenticated, machine key sprawl, SFTP versus FTPS, tunnelling, and how to govern SSH keys and certificates alongside TLS certificates. For TLS internals, see the How TLS Works Guide; for SSH key operations, see the SSH Key Management Guide.
Status line (checked 14 November 2026): TLS 1.3 is now specified in RFC 9846 (Proposed Standard, July 2026), a minor update that obsoletes RFC 8446 and keeps the same version number. SSH is specified in RFC 4251 to RFC 4254. OpenSSH behaviour is taken from the current OpenBSD manual pages.
Key takeaways
- Different trust anchors. RFC 4251 describes two SSH host key models, a local database of known keys or CA-certified host keys; TLS relies on X.509 certificate chains to roots in a trust store. Most SSH estates still run the first model.
- Trust on first use is an active-attack gap. RFC 4251 says accepting an unknown host key protects against passive eavesdropping but not an active man-in-the-middle, and should not be the default. In practice it usually is, which is why host certificates or SSHFP with DNSSEC matter.
- Client authentication is normal in SSH, optional in TLS. SSH always authenticates the user (RFC 4252); TLS 1.3 always authenticates the server and authenticates the client only when asked. Mutual TLS is the exception you design for, SSH user auth is the rule.
- SSH keys sprawl because they never expire by default. An authorized_keys entry has no expiry or owner, and an OpenSSH certificate signed without a validity interval is valid from the Unix Epoch to the distant future. Short-lived certificates fix both, if you set lifetimes deliberately.
- Pick by job, not by habit. Use TLS for services and APIs reached by many clients, SSH for administrative access and host-to-host automation, and SFTP rather than FTPS for new file transfer unless a partner mandates FTPS.
The short answer
Use TLS when unknown or numerous clients connect to a service, when public trust matters (browsers, mobile apps, partner APIs), and when you need standard tooling such as load balancers, certificate transparency and managed certificate lifecycles. Use SSH when a person or system needs a shell, remote command execution or file transfer on a host it is entitled to administer, and when you control both ends. The overlap areas are file transfer (SFTP over SSH versus FTPS over TLS), tunnelling (SSH port forwarding versus TLS-based VPNs and proxies) and machine-to-machine authentication (SSH user keys versus mutual TLS client certificates). In those, the deciding factor is usually who manages identities and how you will revoke them, not raw security strength.
Side by side
| Dimension | SSH | TLS |
|---|---|---|
| Specification | RFC 4251 architecture, 4252 user authentication, 4253 transport, 4254 connection | RFC 9846 (TLS 1.3, obsoletes RFC 8446 and RFC 5246) |
| Default port | 22 (sshd Port default) | Depends on the application protocol, for example 443 for HTTPS |
| Server identity | Host key, trusted via known_hosts, host certificate or SSHFP | X.509 certificate chained to a trusted root |
| Client identity | Always: public key, password, keyboard-interactive or certificate | Optional: client certificate on CertificateRequest, or PSK |
| Certificate format | OpenSSH certificates, a simpler non-X.509 format with principals and options | X.509 with names in Subject Alternative Name, extensions and chains |
| Revocation | Key Revocation Lists (KRL) distributed to servers via RevokedKeys | CRL, OCSP and, increasingly, short lifetimes |
| Channel model | Many multiplexed channels in one connection: shells, exec, subsystems, forwarding | One byte stream per connection carrying one application protocol |
| Typical authorisation | Server-side: account, authorized_keys options, principals, ForceCommand | In the application above TLS: tokens, sessions, roles |
| Public ecosystem | No public CA system | Public CAs, browser root programmes, certificate transparency |
Trust models: TOFU host keys versus CA-based PKI
SSH by default: the first time a client meets a server, it shows a fingerprint and asks the user to accept it, then stores the key in known_hosts and compares it on later connections. RFC 4251 is clear that this protects against passive eavesdropping but leaves a first-connection active attack open, and recommends that implementations should not allow unchecked acceptance by default. Users click "yes" because nothing tells them what the right fingerprint is.
Closing the gap in SSH: three options exist. Distribute known_hosts centrally through configuration management. Publish SSHFP records (RFC 4255, DNS type 44), which are only trustworthy when DNSSEC authenticates them. Or sign host keys with an SSH CA (ssh-keygen -h, with HostCertificate in sshd_config) so clients trust one CA line instead of thousands of host entries. RFC 4251 notes the trade-off: the CA model is easier to maintain but depends heavily on that central infrastructure.
TLS by default: the client validates the server certificate chain to a trusted root and checks that the requested name matches the certificate. There is no first-use prompt; trust is delegated to CAs and to the trust store owner. The risks move to CA compromise, mis-issuance, weak validation in custom clients and private CAs whose roots are installed too widely. See the Certificate trust stores and root CA management.
The GitHub RSA SSH host key exposure in 2023 shows the TOFU model under stress: after the key was replaced, every RSA client hit a host identification warning and had to update known_hosts by hand, and automated workflows failed until updated. A host CA or centrally pushed known_hosts turns that into a configuration change.
Authenticating both ends
SSH: the transport layer authenticates the server (RFC 4253), then the user authentication layer authenticates the client (RFC 4252). Every session has an authenticated user identity on the server, which is why SSH is natural for privileged access. The weak spots are password authentication (PasswordAuthentication defaults to yes in sshd_config) and static user keys with no owner or expiry.
TLS: TLS 1.3 always authenticates the server and authenticates the client only if the server sends CertificateRequest. Most deployments authenticate users above TLS with passwords, tokens or session cookies. Mutual TLS adds client certificates, which suits service-to-service traffic but brings issuance and rotation work for every client. See the Mutual TLS vs TLS.
| Need | SSH approach | TLS approach |
|---|---|---|
| Prove the server is genuine | Host certificate signed by an SSH CA, or SSHFP with DNSSEC | Publicly or privately issued X.509 server certificate |
| Prove the human is genuine | User certificate after SSO and MFA, or hardware-backed key (verify-required for FIDO keys) | Application login with MFA, optionally client certificate |
| Prove a workload is genuine | Short-lived user certificate with restricted principals and options | mTLS client certificate or a signed token over TLS |
| Restrict what the client can do | Certificate options: force-command, source-address, no-port-forwarding, no-pty | Application authorisation, scopes and roles |
| Revoke quickly | KRL pushed to RevokedKeys, or let short certificates expire | Short certificate lifetimes, OCSP or CRL where clients check them |
Machine key sprawl: SSH keys versus TLS certificates
NIST IR 7966 (2015) focuses on SSH user keys used for automated access, such as file transfers, disaster recovery, patching and cloud provisioning, and observes that key-based access had been largely ignored. The problem is structural. A raw public key in authorized_keys has no issuer, no expiry, no owner field and no central record, and copying a private key to a new system silently extends access. TLS certificates have issuers, expiry dates and, for public certificates, transparency logs, so discovery is easier; the TLS failure mode is expiry outages and unmanaged private CAs rather than invisible grants.
- SSH governance target: replace static keys with short-lived OpenSSH user certificates issued by a CA after authentication, with a key identifier (-I) logged on use, explicit principals (-n) and a deliberate validity (-V). Configure TrustedUserCAKeys and, where account names differ from principals, AuthorizedPrincipalsFile.
- TLS governance target: automated issuance and renewal (ACME or a managed CA), short lifetimes, a certificate inventory and ownership per certificate. See the Machine Identity, PKI and Certificate Lifecycle Guide.
- Shared lesson: both protocols put long-lived private keys on machines. Treat each as a non-human identity with an owner, a purpose, a lifetime and a revocation path.
To find what you have today, see How to Find ssh authorized keys across a server fleet.
SFTP vs FTPS
SFTP is not FTP over SSH; it is a separate file transfer protocol run as the "sftp" subsystem of the SSH connection protocol. The version most implementations follow is protocol version 3 from draft-ietf-secsh-filexfer-02, an Internet-Draft from October 2001 that is now expired and was never published as an RFC. FTPS is classic FTP secured with TLS: RFC 4217 has the client send AUTH TLS on the control connection (port 21), and protect data connections with PBSZ 0 and PROT P.
| Factor | SFTP (SSH) | FTPS (TLS) |
|---|---|---|
| Connections | One SSH connection, usually port 22 | Control connection plus separate data connections |
| Firewalls and NAT | Simple: one port | Hard: encrypted control traffic hides the data port negotiation from inspecting firewalls (RFC 4217) |
| Server identity | Host key or host certificate | X.509 server certificate |
| Client identity | SSH keys, certificates or passwords | Username and password, optionally client certificates |
| Partial protection risks | Encrypted throughout | Data channels start unprotected until PROT P; CCC returns control to plaintext and RFC 4217 warns of its risks |
| Restricting users | internal-sftp with ChrootDirectory and ForceCommand, no shell | Server-specific virtual users and directory permissions |
| Standards status | Expired Internet-Draft, widely implemented | RFC 4217 Proposed Standard, updated by RFC 8996 |
Decision: choose SFTP for new partner and internal transfers because one port, one trust model and SSH certificates make it easier to run. Choose FTPS when a partner, regulator or legacy platform requires it, or when you need X.509 client certificates issued by an existing PKI. In either case, give each partner its own account and credential, restrict it to a directory, and log every transfer. Note that sshd defines no subsystems by default, so the sftp subsystem must be configured explicitly.
Tunnelling and forwarding
RFC 4254 lets one SSH connection carry local port forwarding (direct-tcpip channels), remote forwarding (tcpip-forward requests that open listeners on the server side) and X11 forwarding, alongside agent forwarding in OpenSSH. sshd_config defaults are permissive: AllowTcpForwarding yes and AllowAgentForwarding yes, with PermitOpen allowing all destinations unless set. That makes SSH a ready-made tunnel for attackers who obtain a key, mapped in ATT&CK as T1572 Protocol Tunneling and lateral movement through T1021.004 SSH.
TLS has no built-in forwarding; tunnels over TLS come from products layered on top (VPNs, reverse proxies, connectors). That separation makes TLS tunnels easier to govern centrally but also lets malware hide command and control inside ordinary-looking HTTPS. See the TLS Inspection vs Encrypted Traffic Analysis.
- Restrict SSH forwarding: set AllowTcpForwarding no and AllowAgentForwarding no by default, enable per group with Match blocks, keep GatewayPorts no and PermitTunnel no, and use PermitOpen where forwarding is needed.
- Prefer jump hosts to agent forwarding: see the SSH Agent Forwarding vs ProxyJump.
- Encode restrictions in certificates: issue automation certificates with no-port-forwarding, no-agent-forwarding, no-pty and force-command so a stolen credential cannot become a general tunnel.
Worked scenario: a payments platform
A payments company runs customer APIs, an internal microservice mesh, 2,000 Linux hosts and nightly file exchanges with ten banks. Customer APIs use TLS with public certificates, renewed automatically. Service-to-service calls use mutual TLS with a private CA and 24-hour certificates. Administrators reach hosts through a bastion using SSH user certificates valid for eight hours, issued after SSO with MFA, with host certificates on every server so known_hosts prompts disappear. Deployment automation uses SSH certificates with force-command limited to the deploy script, source-address set to the CI runners and a one-hour validity. Eight banks receive files over SFTP into chrooted internal-sftp accounts; two require FTPS with client certificates, which run on a separate hardened gateway with CCC refused. The team inventories remaining static authorized_keys entries quarterly and removes any without an owner, aiming for zero.
How to implement
- Inventory both estates: SSH servers, authorized_keys entries, known_hosts practices and private keys on automation hosts; TLS endpoints, certificates, issuing CAs and trust stores.
- Decide protocol by use case: document which flows use TLS, SSH, SFTP or FTPS and why, and flag exceptions.
- Stand up an SSH CA: protect the CA key in an HSM or secrets platform, issue host certificates first (low risk, removes TOFU prompts), then user certificates for a pilot group.
- Pilot and test: run certificates alongside existing keys on a pilot ring, confirm logins and automation, check that the key identifier appears in logs.
- Tighten server configuration: disable password authentication, restrict forwarding, set RevokedKeys to a distributed KRL. See the OpenSSH Server Hardening Guide.
- Remove static keys: migrate automation to short-lived certificates or brokered access, then delete orphaned authorized_keys entries.
- Roll back safely: keep a break-glass account with a hardware-protected key during migration, and keep the previous authorized_keys files under version control until certificate access is proven.
- Align TLS lifecycle: automate renewal, set lifetimes and assign owners for every certificate so both protocols share one machine identity register.
Detection and measurement
- SSH logs: accepted and failed authentications with method and certificate key identifier, new authorized_keys entries (ATT&CK T1098.004 SSH Authorized Keys), forwarding requests and logins from unexpected sources. See the Linux SSH and Authentication Log Detection Guide.
- TLS telemetry: certificate expiry, unexpected issuers, handshake failures and client certificate failures at gateways.
- Private key theft: watch for reads of private key files by unusual processes (T1552.004 Private Keys).
- Metric 1: percentage of SSH logins using certificates rather than static keys or passwords.
- Metric 2: count of authorized_keys entries with no recorded owner, trending to zero.
- Metric 3: percentage of servers presenting host certificates.
- Metric 4: median SSH user certificate lifetime and TLS certificate lifetime.
- Metric 5: file transfer partners on SFTP or FTPS with per-partner credentials, against total partners.
Common failure patterns
- Training users to click yes: TOFU prompts with no published fingerprints turn host verification into a habit, so a real man-in-the-middle prompt looks normal.
- Certificates without lifetimes: signing SSH certificates without -V leaves them valid indefinitely, recreating static keys with extra steps.
- One CA for everything: a single SSH CA for hosts and users, or one private TLS CA trusted by every device, means one key compromise reaches the whole estate.
- Forwarding left on: default AllowTcpForwarding and AllowAgentForwarding let any stolen automation key act as a network tunnel.
- FTPS half-protected: data channels left on PROT C or CCC allowed, so files or commands cross the network in clear.
- Host key rotation with no plan: replacing a host key without a host CA or central known_hosts breaks automation and teaches users to ignore warnings.
Framework mapping
| Framework | Reference | How it applies |
|---|---|---|
| NIST SP 800-53 Rev. 5 | SC-8 Transmission Confidentiality and Integrity, SC-23 Session Authenticity | Both protocols protect channels; host and server authentication protect session authenticity |
| NIST SP 800-53 Rev. 5 | SC-12, SC-17, IA-5 | Key management, PKI certificates (X.509 and SSH CA) and authenticator lifetimes |
| NIST SP 800-53 Rev. 5 | IA-3, AC-6, CM-7 | Device and workload authentication, least privilege in certificate options, disabling unneeded forwarding |
| NIST CSF 2.0 | PR.DS-02, PR.AA-01, PR.AA-03 | Data in transit protected; identities managed; users, services and hardware authenticated |
| ISO/IEC 27001:2022 Annex A | A.8.20 Networks security, A.8.24 Use of cryptography | Secure channels and cryptographic key rules |
| MITRE ATT&CK | T1021.004, T1098.004, T1552.004, T1572, T1557 | SSH lateral movement, authorized keys persistence, private key theft, tunnelling and man-in-the-middle |
Practitioner checklist
- Map every encrypted flow to TLS, SSH, SFTP or FTPS with a documented reason.
- Issue SSH host certificates or distribute known_hosts centrally to remove first-use prompts.
- Move people and automation to short-lived SSH user certificates with explicit principals and validity.
- Keep separate CAs for SSH hosts, SSH users and TLS, each with protected keys.
- Disable SSH password authentication and default forwarding; enable forwarding only where justified.
- Distribute a KRL to every server through RevokedKeys and test it.
- Prefer SFTP for new file transfer; on FTPS require PROT P and refuse CCC.
- Automate TLS certificate renewal and assign an owner to every certificate.
- Remove authorized_keys entries with no owner on a fixed cycle.
Standards and references
- IETF: RFC 4251 The Secure Shell (SSH) Protocol Architecture
- IETF: RFC 4254 The Secure Shell (SSH) Connection Protocol
- IETF: RFC 9846 The Transport Layer Security (TLS) Protocol Version 1.3
- IETF: RFC 4217 Securing FTP with TLS
- IETF: RFC 4255 Using DNS to Securely Publish SSH Key Fingerprints
- NIST: IR 7966 Security of Interactive and Automated Access Management Using Secure Shell
- OpenBSD: ssh-keygen(1) manual page
- OpenBSD: sshd_config(5) manual page
Related NHI Mgmt Group resources: SSH Key Management Guide · How TLS Works Guide · Mutual TLS vs TLS · Security Keys for SSH · PQC SSH Migration Guide