# Secure Shell

The Secure Shell Protocol (SSH Protocol) is a cryptographic network protocol for operating network services securely over an unsecured network. Its most notable applications are remote login and command-line execution.
SSH was designed for Unix-like operating systems as a replacement for Telnet and unsecured remote Unix shell protocols, such as the Berkeley Remote Shell (rsh) and the related rlogin and rexec protocols, which all use insecure, plaintext methods of authentication, like passwords.
Since mechanisms like Telnet and Remote Shell are designed to access and operate remote computers, sending the authentication tokens (e.g. username and password) for this access to these computers across a public network in an unsecured way poses a great risk of 3rd parties obtaining the password and achieving the same level of access to the remote system as the telnet user. Secure Shell mitigates this risk through the use of encryption mechanisms that are intended to hide the contents of the transmission from an observer, even if the observer has access to the entire data stream.
Finnish computer scientist Tatu Ylönen designed SSH in 1995 and provided an implementation in the form of two commands, ssh and slogin, as secure replacements for rsh and rlogin, respectively. Subsequent development of the protocol suite proceeded in several developer groups, producing several variants of implementation. The protocol specification distinguishes two major versions, referred to as SSH-1 and SSH-2. The most commonly implemented software stack is OpenSSH, released in 1999 as open-source software by the OpenBSD developers. Implementations are distributed for all types of operating systems in common use, including embedded systems.
SSH applications are based on a client–server architecture, connecting an SSH client instance with an SSH server. SSH operates as a layered protocol suite comprising three principal hierarchical components: the transport layer provides server authentication, confidentiality, and integrity; the user authentication protocol validates the user to the server; and the connection protocol multiplexes the encrypted tunnel into multiple logical communication channels.

## Definition

SSH uses public-key cryptography to authenticate the remote computer and allow it to authenticate the user, if necessary.
SSH may be used in several methodologies. In the simplest manner, both ends of a communication channel use automatically generated public-private key pairs to encrypt a network connection, and then use a password to authenticate the user.
When the public-private key pair is generated by the user manually, the authentication is essentially performed when the key pair is created, and a session may then be opened automatically without a password prompt. In this scenario, the public key is placed on all computers that must allow access to the owner of the matching private key, which the owner keeps private. While authentication is based on the private key, the key is never transferred through the network during authentication. SSH only verifies that the same person offering the public key also owns the matching private key.
In all versions of SSH it is important to verify unknown public keys, i.e. associate the public keys with identities, before accepting them as valid. Accepting an attacker's public key without validation will authorize an unauthorized attacker as a valid user.

## Authentication: OpenSSH key management

On Unix-like systems, the list of authorized public keys is typically stored in the home directory of the user that is allowed to log in remotely, in the file ~/.ssh/authorized_keys. This file is respected by SSH only if it is not writable by anything apart from the owner and root. When the public key is present on the remote end and the matching private key is present on the local end, typing in the password is no longer required. However, for additional security the private key itself can be locked with a passphrase.
The private key can also be looked for in standard places, and its full path can be specified as a command line setting (the option -i for ssh). The ssh-keygen utility produces the public and private keys, always in pairs.

## Use

SSH is typically used to log into a remote computer's shell or command-line interface (CLI) and to execute commands on a remote server. It also supports mechanisms for tunneling, forwarding of TCP ports and X11 connections and it can be used to transfer files using the associated SSH File Transfer Protocol (SFTP) or Secure Copy Protocol (SCP).
SSH uses the client–server model. An SSH client program is typically used for establishing connections to an SSH daemon, such as sshd, accepting remote connections. Both are commonly present on most modern operating systems, including macOS, most distributions of Linux, OpenBSD, FreeBSD, NetBSD, Solaris and OpenVMS. Notably, versions of Windows prior to Windows 10 version 1709 do not include SSH by default, but proprietary, freeware and open source versions of various levels of complexity and completeness did and do exist (see Comparison of SSH clients). In 2018 Microsoft began porting the OpenSSH source code to Windows and in Windows 10 version 1709, an official Win32 port of OpenSSH is now available.
File managers for UNIX-like systems (e.g. Konqueror) can use the FISH protocol to provide a split-pane GUI with drag-and-drop. The open source Windows program WinSCP provides similar file management (synchronization, copy, remote delete) capability using PuTTY as a back-end. Both WinSCP and PuTTY are available packaged to run directly off a USB drive, without requiring installation on the client machine. Crostini on ChromeOS comes with OpenSSH by default. Setting up an SSH server in Windows typically involves enabling a feature in the Settings app.
SSH is important in cloud computing to solve connectivity problems, avoiding the security issues of exposing a cloud-based virtual machine directly on the Internet. An SSH tunnel can provide a secure path over the Internet, through a firewall to a virtual machine.
The IANA has assigned TCP port 22, UDP port 22 and SCTP port 22 for this protocol. IANA had listed the standard TCP port 22 for SSH servers as one of the well-known ports as early as 2001. SSH can also be run using SCTP rather than TCP as the connection oriented transport layer protocol.

## Historical development
### Version 1

In 1995, Tatu Ylönen, a researcher at Helsinki University of Technology in Finland designed the first version of the protocol (now called SSH-1) prompted by a password-sniffing attack at his university network. The goal of SSH was to replace the earlier rlogin, TELNET, FTP and rsh protocols, which did not provide strong authentication nor guarantee confidentiality. He chose the port number 22 because it is between telnet (port 23) and ftp (port 21).
Ylönen released his implementation as freeware in July 1995, and the tool quickly gained in popularity. Towards the end of 1995, the SSH user base had grown to 20,000 users in fifty countries.
In December 1995, Ylönen founded SSH Communications Security to market and develop SSH. The original version of the SSH software used various pieces of free software, such as GNU libgmp, but later versions released by SSH Communications Security evolved into increasingly proprietary software.
It was estimated that by 2000 the number of users had grown to 2 million.

### Version 2

In 2006, after being discussed in a working group named "secsh", a revised version of the SSH protocol, SSH-2 was adopted as a standard. This version offers improved security and new features, but is not compatible with SSH-1. For example, it introduces new key-exchange mechanisms like Diffie–Hellman key exchange, improved data integrity checking via message authentication codes like MD5 or SHA-1, which can be negotiated between client and server. SSH-2 also adds stronger encryption methods like AES which eventually replaced weaker and compromised ciphers from the previous standard like 3-des. New features of SSH-2 include the ability to run any number of shell sessions over a single SSH connection. Due to SSH-2's superiority and popularity over SSH-1, some implementations such as libssh (v0.8.0+), Lsh and Dropbear eventually supported only the SSH-2 protocol.

### Version 1.99

In January 2006, well after version 2.1 was established, RFC 4253 specified that an SSH server supporting 2.0 as well as prior versions should identify its protocol version as 1.99. This version number does not reflect a historical software revision, but a method to identify backward compatibility.

### OpenSSH and OSSH

In 1999, developers, desiring availability of a free software version, restarted software development from the 1.2.12 release of the original SSH program, which was the last released under an open source license. This served as a code base for Björn Grönvall's OSSH software. Shortly thereafter, OpenBSD developers forked Grönvall's code and created OpenSSH, which shipped with Release 2.6 of OpenBSD. From this version, a "portability" branch was formed to port OpenSSH to other operating systems.
As of 2005, OpenSSH was the single most popular SSH implementation, being the default version in a large number of operating system distributions. OSSH meanwhile has become obsolete. OpenSSH continues to be maintained and supports the SSH-2 protocol, having expunged SSH-1 support from the codebase in the OpenSSH 7.6 release.

### Future

In 2023, an alternative to traditional SSH was proposed under the name SSH3 by PhD student François Michel and Professor Olivier Bonaventure and its code has been made open source. This new version implements the original SSH Connection Protocol but operates on top of HTTP/3, which runs on QUIC. It offers multiple features such as:
* Faster session establishment, reducing the number of Round-trip delays from 5-7 to 3.
* High security: while SSHv2 relies on its own protocols, SSH3 leverages TLS 1.3, QUIC, and HTTP.
* UDP port forwarding
* X.509 certificates
* OpenID Connect
However, the name SSH3 is under discussion, and the project aims to rename itself to a more suitable name. The discussion stems from the fact that this new implementation significantly revises the SSH protocol, suggesting it should not be called SSH3.

## Uses

SSH is a protocol that can be used for many applications across many platforms including most Unix variants (Linux, the BSDs including Apple's macOS, and Solaris), as well as Microsoft Windows. Some of the applications below may require features that are only available or compatible with specific SSH clients or servers. For example, using the SSH protocol to implement a VPN is possible, but presently only with the OpenSSH server and client implementation.
* For login to a shell on a remote host (replacing Telnet and rlogin)
* For executing a single command on a remote host (replacing rsh)
* For setting up automatic (passwordless) login to a remote server (for example, using OpenSSH)
* In combination with rsync to back up, copy and mirror files efficiently and securely
* For forwarding a port
* For tunneling (not to be confused with a VPN, which routes packets between different networks, or bridges two broadcast domains into one).
* For using as a full-fledged encrypted VPN. Note that only OpenSSH server and client supports this feature.
* For forwarding X from a remote host (possible through multiple intermediate hosts)
* For browsing the web through an encrypted proxy connection with SSH clients that support the SOCKS protocol.
* For securely mounting a directory on a remote server as a filesystem on a local computer using SSHFS.
* For automated remote monitoring and management of servers through one or more of the mechanisms discussed above.
* For development on a mobile or embedded device that supports SSH.
* For securing file transfer protocols.

### File transfer protocols

The Secure Shell protocols are used in several file transfer mechanisms.
* Secure copy (SCP), which evolved from RCP protocol over SSH
* rsync, intended to be more efficient than SCP. Generally runs over an SSH connection.
* SSH File Transfer Protocol (SFTP), a secure alternative to FTP (not to be confused with FTP over SSH or FTPS)
* Files transferred over shell protocol (FISH), released in 1998, which evolved from Unix shell commands over SSH
* Fast and Secure Protocol (FASP), aka Aspera, uses SSH for control and UDP ports for data transfer.

## Architecture

The SSH protocol has a layered architecture with three separate components:
* The transport layer (RFC 4253) typically uses the Transmission Control Protocol (TCP) of TCP/IP, reserving port number 22 as a server listening port. This layer handles initial key exchange as well as server authentication, and sets up encryption, compression, and integrity verification. It exposes to the upper layer an interface for sending and receiving plaintext packets with a size of up to 32,768 bytes each, but more can be allowed by each implementation. The transport layer also arranges for key re-exchange, usually after 1 GB of data has been transferred or after one hour has passed, whichever occurs first.
* The user authentication layer (RFC 4252) handles client authentication, and provides a suite of authentication algorithms. Authentication is client-driven: when one is prompted for a password, it may be the SSH client prompting, not the server. The server merely responds to the client's authentication requests. Widely used user-authentication methods include the following:
** password: a method for straightforward password authentication, including a facility allowing a password to be changed. Not all programs implement this method.
** publickey: a method for public-key-based authentication, usually supporting at least DSA, ECDSA or RSA keypairs, with other implementations also supporting X.509 certificates.
** keyboard-interactive (RFC 4256): a versatile method where the server sends one or more prompts to enter information and the client displays them and sends back responses keyed-in by the user. Used to provide one-time password authentication such as S/Key or SecurID. Used by some OpenSSH configurations when PAM is the underlying host-authentication provider to effectively provide password authentication, sometimes leading to inability to log in with a client that supports just the plain password authentication method.
** GSSAPI authentication methods which provide an extensible scheme to perform SSH authentication using external mechanisms such as Kerberos 5 or NTLM, providing single sign-on capability to SSH sessions. These methods are usually implemented by commercial SSH implementations for use in organizations, though OpenSSH does have a working GSSAPI implementation.
* The connection layer (RFC 4254) defines the concept of channels, channel requests, and global requests, which define the SSH services provided. A single SSH connection can be multiplexed into multiple logical channels simultaneously, each transferring data bidirectionally. Channel requests are used to relay out-of-band channel-specific data, such as the changed size of a terminal window, or the exit code of a server-side process. Additionally, each channel performs its own flow control using the receive window size. The SSH client requests a server-side port to be forwarded using a global request. Standard channel types include:
** shell for terminal shells, SFTP and exec requests (including SCP transfers)
** direct-tcpip for client-to-server forwarded connections
** forwarded-tcpip for server-to-client forwarded connections
* The SSHFP DNS record (RFC 4255) provides the public host key fingerprints in order to aid in verifying the authenticity of the host.
This open architecture provides considerable flexibility, allowing the use of SSH for a variety of purposes beyond a secure shell. The functionality of the transport layer alone is comparable to Transport Layer Security (TLS); the user-authentication layer is highly extensible with custom authentication methods; and the connection layer provides the ability to multiplex many secondary sessions into a single SSH connection, a feature comparable to BEEP and not available in TLS.

## Algorithms

* EdDSA, ECDSA, RSA and DSA for public-key cryptography.
* ECDH and Diffie–Hellman for key exchange.
* HMAC, AEAD and UMAC for MAC.
* AES (and deprecated RC4, 3DES, DES) for symmetric encryption.
* AES-GCM and ChaCha20-Poly1305 for AEAD encryption.
* SHA (and deprecated MD5) for key fingerprint.

## Vulnerabilities
### SSH-1

In 1998, a vulnerability was described in SSH 1.5 which allowed the unauthorized insertion of content into an encrypted SSH stream due to insufficient data integrity protection from CRC-32 used in this version of the protocol. A fix known as SSH Compensation Attack Detector was introduced into most implementations. Many of these updated implementations contained a new integer overflow vulnerability that allowed attackers to execute arbitrary code with the privileges of the SSH daemon, typically root.
In January 2001 a vulnerability was discovered that allows attackers to modify the last block of an IDEA-encrypted session. The same month, another vulnerability was discovered that allowed a malicious server to forward a client authentication to another server.
Since SSH-1 has inherent design flaws which make it vulnerable, it is now generally considered obsolete and should be avoided by explicitly disabling fallback to SSH-1. Most modern servers and clients support SSH-2.

### CBC plaintext recovery

In November 2008, a theoretical vulnerability was discovered for all versions of SSH which allowed recovery of up to 32 bits of plaintext from a block of ciphertext that was encrypted using what was then the standard default encryption mode, CBC. The most straightforward solution is to use CTR, counter mode, instead of CBC mode, since this renders SSH resistant to the attack.

### Suspected decryption by NSA

On December 28, 2014 Der Spiegel published classified information leaked by whistleblower Edward Snowden which suggests that the National Security Agency may be able to decrypt some SSH traffic. The technical details associated with such a process were not disclosed. A 2017 analysis of the CIA hacking tools BothanSpy and Gyrfalcon suggested that the SSH protocol was not compromised.

### Terrapin attack

A novel man-in-the-middle attack against most current ssh implementations was discovered in 2023. It was named the Terrapin attack by its discoverers. However, the risk is mitigated by the requirement to intercept a genuine ssh session, and that the attack is restricted in its scope, fortuitously resulting mostly in failed connections. The ssh developers have stated that the major impact of the attack is to degrade the keystroke timing obfuscation features of ssh. The vulnerability was fixed in OpenSSH 9.6, but requires both client and server to be upgraded for the fix to be fully effective.

## Standards documentation

The following RFC publications by the IETF "secsh" working group document SSH-2 as a proposed Internet standard.
* RFC 4250 – The Secure Shell (SSH) Protocol Assigned Numbers
* RFC 4251 – The Secure Shell (SSH) Protocol Architecture
* RFC 4252 – The Secure Shell (SSH) Authentication Protocol
* RFC 4253 – The Secure Shell (SSH) Transport Layer Protocol
* RFC 4254 – The Secure Shell (SSH) Connection Protocol
* RFC 4255 – Using DNS to Securely Publish Secure Shell (SSH) Key Fingerprints
* RFC 4256 – Generic Message Exchange Authentication for the Secure Shell Protocol (SSH)
* RFC 4335 – The Secure Shell (SSH) Session Channel Break Extension
* RFC 4344 – The Secure Shell (SSH) Transport Layer Encryption Modes
* RFC 4345 – Improved Arcfour Modes for the Secure Shell (SSH) Transport Layer Protocol
The protocol specifications were later updated by the following publications:
* RFC 4419 – Diffie-Hellman Group Exchange for the Secure Shell (SSH) Transport Layer Protocol (March 2006)
* RFC 4432 – RSA Key Exchange for the Secure Shell (SSH) Transport Layer Protocol (March 2006)
* RFC 4462 – Generic Security Service Application Program Interface (GSS-API) Authentication and Key Exchange for the Secure Shell (SSH) Protocol (May 2006)
* RFC 4716 – The Secure Shell (SSH) Public Key File Format (November 2006)
* RFC 4819 – Secure Shell Public Key Subsystem (March 2007)
* RFC 5647 – AES Galois Counter Mode for the Secure Shell Transport Layer Protocol (August 2009)
* RFC 5656 – Elliptic Curve Algorithm Integration in the Secure Shell Transport Layer (December 2009)
* RFC 6187 – X.509v3 Certificates for Secure Shell Authentication (March 2011)
* RFC 6239 – Suite B Cryptographic Suites for Secure Shell (SSH) (May 2011)
* RFC 6594 – Use of the SHA-256 Algorithm with RSA, Digital Signature Algorithm (DSA), and Elliptic Curve DSA (ECDSA) in SSHFP Resource Records (April 2012)
* RFC 6668 – SHA-2 Data Integrity Verification for the Secure Shell (SSH) Transport Layer Protocol (July 2012)
* RFC 7479 – Ed25519 SSHFP Resource Records (March 2015)
* RFC 5592 – Secure Shell Transport Model for the Simple Network Management Protocol (SNMP) (June 2009)
* RFC 6242 – Using the NETCONF Protocol over Secure Shell (SSH) (June 2011)
* RFC 8332 – Use of RSA Keys with SHA-256 and SHA-512 in the Secure Shell (SSH) Protocol (March 2018)
* RFC 8709 – Ed25519 and Ed448 Public Key Algorithms for the Secure Shell (SSH) Protocol (February 2020)
* draft-gerhards-syslog-transport-ssh-00 – SSH transport mapping for SYSLOG (July 2006)
* draft-ietf-secsh-filexfer-13 – SSH File Transfer Protocol (July 2006)
* draft-ietf-sshm-ssh-agent - SSH Agent Protocol (June 2025)
In addition, the OpenSSH project includes several vendor protocol specifications/extensions:
* OpenSSH PROTOCOL overview
* OpenSSH certificate/key overview
* OpenSSH FIDO/u2f support