Basically, the procedure is:
- The client connects to the server and asks for the server's certificate. The certificate contains the public key and information about the server's identity.
- Assuming the client is happy with the server's identity, it generates a random number P and encrypts it with the server's public key.
- Only the server can decrypt P (with it's private key - not shared with anybody) so when the client sends the encrypted random number to the server, the server decrypts it.
- The client and server both use P to generate a symmetric key for use in a symmetric encryption algorithm, safe in the knowledge that only the client and server know the value of P used to generate the key.