1. The SSH client contacts the SSH server
2. Both client and server disclose the SSH protocol versions they support
3. The remote host identifies itself to the SSH client by sending the following data,
unencrypted:
a. The remote host's public key (a discussion of public-key cryptography will
follow in the next section)
b. In the case of SSH1, the public key for the SSH server (note that there
might be more than one SSH server for a given host)
c. A sequence of random bytes called check bytes, to foil against IP
spoofing. The client must then include these in its next response or the
connection request will be rejected
d. A list of encryption, compression, and authentication methods supported
by the SSH server. Both sides then compute and exchange what is known
as a session identifier, a common 128-bit session identifier that is a MD5
hash of the host key, server key, and check bytes taken together. The
client checks the host public key against $HOME/.SSH/known_hosts and
/etc/known_hosts.
4. A bulk cipher is generated for the session. Known as the session key, its purpose
is to encrypt and decrypt all data exchanged between client and server. In
addition, the session key plays an important role in guarding against replay
attacks during the user or host authentication phase.
The generation of the session key varies according to whether SSH-1 or SSH-
2 is followed.
Under the SSH-1 protocol, the client formulates the session key, encrypts it
twice with the host public key and the server key (in what is known as perfect
forward secrecy), and sends it to the server.
SSH2 has a different key- exchange procedure, in which both client and server
produce a shared secret that is input to another process, which generates the
session key. Thus, neither side can fully determine the session key as an
additional precaution. And unlike in the SSH-1 protocol, a server key is not
necessary in SSH-2 to produce the session key.
Moreover, in SSH1, only one session key is used throughout the SSH session,
however long the session takes. Potentially, this gives the cryptanalyst more data
encrypted with the same key, and hence greatly increases the chances of the key
being discovered. SSH-2 on the other hand, allows for session rekeying, whereby
a new session key is generated as agreed upon by both client and server.
5. The server sends the client a confirmation message encrypted with the session
key.