# Secure SSH connection setup

By [cyberG|DVS](https://paragraph.com/@cyberg) · 2022-07-08

---

**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.

![](https://storage.googleapis.com/papyrus_images/072f531cafa8e0f3daaf8946ca6ad3be59767d7750fc03a232525e20d8938444.png)

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

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

![](https://storage.googleapis.com/papyrus_images/1dbb260e8b533530ae67e50799b137838ed42f109ecebeb315ed20c2f4bc1ba7.png)

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

![](https://storage.googleapis.com/papyrus_images/8fa01c908058a3b5b7e980e1d9eea3db71c4b7b619eb1b7295aaac34f6b9e378.png)

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.**

---

*Originally published on [cyberG|DVS](https://paragraph.com/@cyberg/secure-ssh-connection-setup)*
