Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How SSH encrypts communications, when using password-based authentication? [closed]

To my understanding, When using SSH with key-based authentication, the server sends a challenge string to the client and client encrypts it with a private key and sends it back to the server, which decrypts it with the public key and ... :

enter image description here

But, how does SSH encrypt communications, when we are using password-based authentication? i.e. how does it generate the key(s) to encrypt the data going from client to server and vice versa?

like image 676
Microsoft Linux TM Avatar asked Oct 17 '25 16:10

Microsoft Linux TM


1 Answers

When you connect through another computer with a password, SSH use a symmetrical encryption:

Symmetrical encryption is often called shared key or shared secret encryption. There is usually only one key that is used, or sometimes a pair keys where one key can easily be calculated using the other key.

Symmetric keys are used to encrypt the entire communication during a SSH Session. Both the client and the server derive the secret key using an agreed method, and the resultant key is never disclosed to any third party. The process of creating a symmetric key is carried out by a key exchange algorithm. What makes this algorithm particularly secure is the fact that the key is never transmitted between the client and the host. Instead, the two computers share public pieces of data and then manipulate it to independently calculate the secret key. Even if another machine captures the publically shared data, it won’t be able to calculate the key because the key exchange algorithm is not known.

It must be noted, however, that the secret token is specific to each SSH session, and is generated prior to client authentication. Once the key has been generated, all packets moving between the two machines must be encrypted by the private key. This includes the password typed into the console by the user, so credentials are always protected from network packet sniffers.

source: https://www.hostinger.com/tutorials/ssh-tutorial-how-does-ssh-work

To encrypts the communication, client and server use the Diffie–Hellman key exchange

Here is how the algorithm works at a very basic level:

  1. Both the client and the server agree on a very large prime number, which of course does not have any factor in common. This prime number value is also known as the seed value.

  2. Next, the two parties agree on a common encryption mechanism to generate another set of values by manipulating the seed values in a specific algorithmic manner. These mechanisms, also known as encryption generators, perform large operations on the seed. An example of such a generator is AES (Advanced Encryption Standard).

  3. Both the parties independently generate another prime number. This is used as a secret private key for the interaction.

  4. This newly generated private key, with the shared number and encryption algorithm (e.g. AES), is used to compute a public key which is distributed to the other computer.

  5. The parties then use their personal private key, the other machine’s shared public key and the original prime number to create a final shared key. This key is independently computed by both computers but will create the same encryption key on both sides.

  6. Now that both sides have a shared key, they can symmetrically encrypt the entire SSH session. The same key can be used to encrypt and decrypt messages (read: section on symmetrical encryption).

Now that the secured symmetrically encrypted session has been established, the user must be authenticated.

like image 52
NoaDeKoKo Avatar answered Oct 20 '25 04:10

NoaDeKoKo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!