How does SSH encryption work

encryptionpublic-key-encryptionssh

I've read about generating 2 keys (private and public) on client host and copying the public key to the server host.

As I understand it, (correct me if i'm wrong): The server encrypts data with the public key and sends it to client, the client decrypts it with the private key.

But if I need to encrypt data on the client for sending to the server, how does it happen?

The public key encrypts data on the client? But how can the server decrypt it, if it only has the public key?

How does SSH encryption work?

Best Answer

First thing after establishing the TCP connection, both systems agree on a session key, using such protocols as DH key exchange, ECDH or GSSAPI. This key is symmetric and temporary – both sides use the same key to encrypt and decrypt data using such algorithms as AES or RC4.

The client keypair is never used for encrypting data, only for authentication – "publickey" is one of several available methods, where the client presents its own public key along with proof of private-key ownership. Similarly, the server keypair is only used for authenticating the server during DH or ECDH key exchanges; no data is encrypted using it.

The SSH2 protocol is documented in several RFCs, including:

  • RFC 4253 – Secure Shell (SSH) Transport Layer Protocol
  • RFC 4419 – Diffie-Hellman Group Exchange
  • RFC 4432 – RSA Key Exchange
  • RFC 4462 – GSSAPI Authentication & Key Exchange
Related Question