Okay, I want to show you how keys are used between the SSH client and the SSHD, which
is the SSH server.
So when a client is initializing contact with the SSHD, the client wants to make sure that
it is talking to the real server.
And that is why this server is signing a key-based ID, and this ID is based on cryptography.
It has been encrypted with the private key of the SSH server, and it will be stored on
the client in the home directory .ssh known hosts.
And the next time you are connecting with the same server, well, the server will always
send over this ID.
And if the ID matches the cryptography for the server entry in known hosts, nothing will
be complained.
But if suddenly the ID doesn't match anymore, you get the message that somebody might be
doing something nasty and you need to verify your work.
Then there is another option to use keys in SSH, and that is where the client is going
to generate some keys.
So there the client would use SSH keygen, and SSH keygen is generating a private key.
And this private key, depending on the encryption algorithm that is used, can be stored in different
ways.
And then the public key is moved over to the server.
And how does that work?
Well, the next time that the client is going to use key-based authentication, it is going
to generate a token, and this token is encrypted with the client's private key, and this token
will be read by the server.
And if it can decrypt it using the public key, then the client is okay and will be authenticated,
and no more passwords will be needed at all.
And that's how keys are used in SSH.