How does SSH work?

When an SSH client connects to the SSH server, the client and the server each send a key to the other. If the keys are trusted, the client and server then negotiate a secret key which is used to encrypt all data exchanged between the two.

Once the secure channel is negotiated and the user is authenticated, files can be transferred through the secured SSH pipeline using SFTP.