Generating and adding an SSH key to connect to a remote GitHub repository

When working with Git, the most used network protocol for transferring data is SSH. There are many reasons for this:
SSH connectivity is present on most servers;
SSH is easy to use and configure;
gives an opportunity for both writing and reading;
no need to constantly enter login and password when making requests to the central server
secure connection on port 22 prevents the possibility of inclusion in the session and interception of data;
data is transmitted in encrypted form;
makes files more compact (compresses) before transferring.
By the way, the hosting provider HyperHost provides SSH on VPS / VDS servers and, on request, on shared hosting tariffs.
The first step is to generate a key pair. This can be done with the command:
ssh-keygen -t rsa -b 4096 -C ““
where is your email, be sure to specify the email that you specified when registering on GitHub.
After entering the command, you can choose the path to save the key or just press Enter, if you want the key to be saved in the default location
You can also enter a passphrase for greater reliability. In the first field we enter the password, in the second we repeat the same phrase for its verification
The next step is to add the generated keys to the SSH agent. To do this, first start the SSH agent with the command:
eval “$ (ssh-agent -s)”
After the command is entered, the terminal displays the id of the running process in the terminal.
Next, as the agent starts, you need to add the generated keys to it with the command:
ssh-add ~ / .ssh / id_rsa
As you can see from the screenshot, the keys were successfully added.
The keys were added, the next step is to copy them and add them to the remote repository. The key can be found along the path indicated on the first screenshot
Or enter the command in the terminal and copy the key to the clipboard:
clip <~ / .ssh /
Then we go into your account on GitHub and follow these steps to add the key
In the Title column, enter a name for the key (indicate which one you want). And in the Key column, add the public key itself and click Add SSH key.