SSH: how it works
The layers of an SSH connection, what happens when you connect, and the words you will see.
SSH (Secure Shell) gives you an encrypted connection to a host. It is used for a shell, for file transfer (SFTP) and to carry other traffic (port forwarding). It replaced Telnet for VT sessions.
What happens when you connect
- TCP connection to the host, port 22 by default.
- Version exchange. Each side says which SSH version it speaks.
- Key exchange. The two sides agree on encryption keys without sending them. The host signs the exchange with its host key so you know you reached the right machine (see Known hosts and fingerprints).
- User authentication. You prove who you are, with a password, a key or a certificate (see Key types).
- Channels. The connection carries one or more channels: a shell or command, an SFTP subsystem, or forwarded ports.
The three layers
SSH is described in three parts (RFC 4251 gives the architecture):
- Transport layer (RFC 4253): encryption, integrity and the host key check.
- User authentication (RFC 4252): password, public key and others.
- Connection layer (RFC 4254): channels, shells and port forwarding.
Vocabulary
- Host key: identifies the server. Checked on every connect.
- User key: identifies you. The private half stays with you, the public half goes into the host's
authorized_keys. - Fingerprint: a short hash of a key you can compare by eye.
- Channel: one stream inside the connection.
- Session: a channel that runs a shell or a command.
What SSH protects
The connection is encrypted and checked for tampering. A host that has your public key cannot learn your private key. SSH does not make a weak password strong, and it does not tell you the host is trustworthy, only that you are talking to the same host as before.