Saturday, November 7, 2015

How Does SSH Work?

If not redirected, please click here

If you are working remotely, especially if you have different servers and you want to login to those servers and work on their shells, rlogin, ssh etc are the options you can take.


SSH is a network protocol that allows remote login and other network services to operate securely over an unsecured network. It was designed basically as a replacement of telnet and other unsecured remote login shell protocols like rsh, rlogin etc.

How is SSH different from others

So, the next question is, how is SSH different from other unsecured remote login shell protocols?

In an unsecured remote login shell protocols, when the server and the client transfers data between them, it is done in an unsecured fashion. So, it is not secure from eavesdropping. In SSH, all the communication between the server and the client is done using encryption and authentication. As a result, data integrity and data security is maintained properly.

How does SSH work

In modern days, mostly we use SSH version 2.

Here is how it works :

SSH uses public key cryptography initially to allow the client to verify the server's authenticity and then to exchange a symmetric key between the server and the client. Later, this symmetric key or session key is used for the rest of the secure communication.

In public key cryptography, a public and private key pair is used for secure communication. So, when a client first communicates with the server, the server sends his public key to the client. The client then verifies the authenticity of the public key of the server with a Certificate Authority.

After that, the server and the client communicates with each other to share a symmetric key between them. To make sure, this communication is secure enough from eavesdropping, Diffie-Hellman key exchange algorithm is used. Please look at this article to know how does Diffie-Hellman key exchange algorithm works.

Once a symmetric key is established between the server and the client, now it is time to authenticate the client to the server. Several mechanisms can be used for this purpose. Password authentication is one such option.

In case of password based authentication, the client sends to the server a password encrypted with the symmetric key. The server verifies it and allows the client for further communication.

But, because of vulnerability regarding password strength etc, this is not a very good option.

Public key cryptography again can be used for this purpose.

In that case, the client first generates a public-private key pair and sends the public key and its key id to the server after generating it. At the time of communication, the client again sends a key id to the server after the symmetric key is established successfully between them.

The server checks the key id and tries to find out a corresponding match of public key from the stored public keys. If a match is found, then the server generates a random number and sends the random number encrypted with the public key of the client.

The client will possess its corresponding private key. So, it will decrypt the random number, and then send a MD5 hash of the random number, encrypting with the session key.

The server now calculates the MD5 hash of the random number it sent and verifies with the bytes it got from the client, decrypted with the session key.

If both the values match, the authenticity of the client is successful. And now, the server and the client can communicate with each other securely, with data encrypted with the session key established between them previously.

So, this is how SSH works and how it is more secure than other unsecured remote login shell protocols. Hope you liked the article.

No comments:

Post a Comment