---
title: 'Connecting to the VPS server via SSH using a key | Zomro'
description: 'In this article, we will look at how to generate a key pair, and connect via SSH using the Putty program.'
image: 'https://cdn.zomro.com/uploads/blog/rostyslav.deichuk%40zomro.org/2026/07/28/1_fO8GEON_q50.jpg'
---

![opened image]()

  * [Zomro](https://zomro.com/)
  * [FAQ](https://zomro.com/blog/faq/)
  * Connecting to the VPS server via SSH using a key 



# Connecting to the VPS server via SSH using a key

15-07-2022

Connecting to the server via SSH using a private key is a good way to secure the connection to your server, and from unnecessary login and password input.  
  
SSH public key authentication is based on cryptographic algorithms that generate a pair of separate keys, private and public. The private key that you use to connect to a remote server is stored on your computer. But you can transfer the public key to anyone without jeopardizing the private one.  
  
For example, you have already bred a server from your personal account. How to do this is described in this article. Next, in your personal account, copy the access data from the Instructions.

  
![Connecting to the VPS server via SSH using a key - 1](https://cdn.zomro.com/uploads/blog/rostyslav.deichuk%40zomro.org/2026/07/28/1_fO8GEON_q50.jpg)  


Next, download the Putty program to connect to the server. Or you can use alternative programs.

  
  
![Connecting to the VPS server via SSH using a key - 2](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2022/07/01/1658856614_01.png)  
In the **Host Name (or IP address)** field, enter the IP of your server. Enter 22 in the **Port** field.  
  
To generate a key pair, there is the **ssh-keygen** utility. It is already installed by default. It generates a pair of 2048-bit RSA keys, which suits us.  
  
On behalf of the user for whom you want to create keys, execute the command (in this case, this is root):  

    
    
    ssh-keygen

  
For questions asked during the generation process, you can simply press Enter. Since our goal is simply to generate a key.  
  
And we get an approximate picture:  
  
![Connecting to the VPS server via SSH using a key - 3](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2022/07/01/1658856639_6.png)  
After that, the contents of the id_rsa.pub file are placed in the **~/.ssh/authorized_keys** file with the following command:
    
    
    cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

  
For security, set the necessary rights:
    
    
    chmod 700 ~/.ssh
    chmod 600 ~/.ssh/authorized_keys

  
  
Now, in order to authorize using the created key, you need to enable key authentication in the **/etc/ssh/sshd_config** file.  
  
To do this, we will edit it.
    
    
    vim /etc/ssh/sshd_config

  
We find the line **PubkeyAuthentication** , uncomment it if it is commented out, and bring it to the form:
    
    
    PubkeyAuthentication yes

  
![Connecting to the VPS server via SSH using a key - 4](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2022/07/01/1658856821_7.png)  
We save the changes.  
  
Then we restart the service:
    
    
    service sshd reload

  
Now we output the key to the console to copy it to our PC.
    
    
    cat ~/.ssh/id_rsa

  
![Connecting to the VPS server via SSH using a key - 5](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2022/07/01/1658856884_8.png)  
Copying from the beginning:
    
    
    -----BEGIN OPENSSH PRIVATE KEY-----

  
To end:
    
    
    -----END OPENSSH PRIVATE KEY-----

  
  
Add to PuttyGen. This program was installed with Putty.  
  
![Connecting to the VPS server via SSH using a key - 6](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2022/07/01/1658856933_9.png)  
After that, save the public and private keys.  
  
![Connecting to the VPS server via SSH using a key - 7](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2022/07/01/1658856922_10.png)  
We can now use the private key to connect via SSH.  
  
To connect it for use in authorization, select it as shown in the figure.  
  
![Connecting to the VPS server via SSH using a key - 8](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2022/07/01/1658856926_11.png)  
After that, we return to the **Session** category, in the **Host Name (or IP address)** field, enter the IP of your server. In the **Port** field, enter 22. In the Saved Sessions field, enter any name, and click Save.  
  
Now to connect by key, select your server from the **Saved Sessions** list, and click **Load** and **Open**.  
  
![Connecting to the VPS server via SSH using a key - 9](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2022/07/01/1658856950_12.png)  
Now you can connect in this way without entering a password, and at the same time protect your connection.  
  
[In the next article, we will further secure our server and connection to it by disabling password authorization and changing the standard port 22 to a non-standard one.](https://zomro.com/blog/faq/236-kak-izmenit-port-podkljuchenija-po-ssh-i-otkljuchit-avtorizaciju-po-parolju)

Similar articles:

[How to disable Defender (Microsoft Defender) in Windows 2016 and 2019](https://zomro.com/blog/faq/347-how-to-activate-microsoft-defender-in-windows-2016-and-2019) [Configuring backups in the ISPmanager panel](https://zomro.com/blog/faq/205-nastrojka-bekapov-v-paneli-ispmanager) [How to install Nginx in Docker-Compose](https://zomro.com/blog/faq/317-kak-ustanovit-nginx-v-docker-compose) [FTP protocol: Detailed information about file transfer](https://zomro.com/blog/faq/447-ftp-protokol-podrobno-o-peredache-fajlov) [How to view and filter Ubuntu server logs](https://zomro.com/blog/faq/359-how-to-view-and-filter-ubuntu-server-logs)

[ Virtual hosting from €3.98/mon ](/virtual)
