Cover photo

Secure SSH connection setup

Hello community. I would like to share with you a guide on setting up a secure SSH connection to your server.

Let's start the computer from which we will connect to the server.

First thing we get is root permissions:

sudo su

Next, generate a private key with this command

ssh-keygen

Next, specify the directory in which you want to save these keys.

Default directory is /root/.ssh/id_rs

Enter a password for your private key.

post image

If you have already created keys, you will see this output

If you choose yes, the previous keys cannot be restores, so be careful.

post image

If you've created a private key , here's what you'll see

post image

Go to the directory ~/.ssh. The following files will be there : id_rsa and id_rsa.pub

Display everything in the id-rsa.pub file

cat ~/.ssh/id_rsa.pub

Next go to the server:

ssh user@ip

Go to directory ~/.ssh

mkdir -p ~/.ssh/ && cd ~/.ssh

Write the public key to the authorized_keys file

Create files with touch authorized_keys

Replace public key with your data.

echo pubkey >> ~/.ssh/authorized_keys

Congratulations. Installation completed. Now you can connect securely using SSH.