Introduction: How the SSH Protocol Works
It will be a relatively small article about how to make a pair of public/private keys for authentication via SSH protocol. Following this, you will learn how to transfer these keys to a remote server and, most importantly, how to use them.
To be able to use this protocol for communication with a remote server, you can use either a password or a pair of public/private keys.
How does it work? First of all, you need to generate a pair of public/private keys on the machine from which you want to connect to the remote server. The private key you keep on the original machine, but the public one you send to the remote server. After a successful transfer, you can log in to the remote server without entering a password. Using key-based authentication is, in any way, faster and more secure and not so annoying.
Generate, transfer, and connect to the server by SSH keys
Let's just clarify one thing: keys pair need to be generated on the machine from which you want to connect to the remote server. Now, how to generate those keys pair:

You will be requested to enter a passphrase; you can skip this step.
Now you need to transfer the generated key, the public one. For this to happen, use this command:
- Flag -i - the path to the public key on the local machine
- Flag -p - the port for connection by SSH Protocol
- root - the user name by which we will interact with the remote server
- 1.1.1.1 - the address of the remote server; it can be a domain name too, if there is one connected
You will be asked to enter a password for the first and the last time. Just do it.
After this, you will easily be able to log in and log out from the server, just using a single command, without additional requests to enter a password. But you need to type a path to the public key like this: