**How to setup an SSH key to your vps**

There are 2 methods for adding SSH keys, both will work but we recommend method 2 here. Both methods have the same first few steps so follow these first.

Step 1: Connect to your VPS in SSH, if you are unsure on how to, refer to our guide using Putty.
Step 2: Run this command: ssh-keygen -t rsa. You will receive a few lines asking you to fill in, refer to the box below if stuck.

For the directory of the key, just hit enter unless you specifically wish to change it, for the passphrase, you can enter a password if you wish to.

Step 3: Run the following commands cd /root/.ssh/ and cat id_rsa.pub. This will give you the values for your SSH key. You want to copy the output. Also note, the directory used in this guide may be changed as well as the file name.

Step 4: Connect to your VPS using SFTP, using the host as your IP address, the username as the username logged into your vps, the password as the same used to login, and the port by default is 22.
If you need to know how to download and set up SFTP, refer to this guide but note the details are different: https://help.skynode.pro/en/article/how-to-manage-files-using-sftp-1dn4a06/

Step 5: Navigate now to the directory on the right where you saved your SSH key, and download the file named what you called it. Download the file without any extension to it.

**Method 1**
Step 1: Login to Virtualizor and go to the SSH keys tab on the side.

Step 2: Add an SSH key, make the identifier as you wish but make then paste the generated key.

Note: The actual key in the screenshot is not valid for security purposes.

Step 3: On your VPS manage page, select the icon of SSH Keys, select your SSH key you just created, and then use key. Restart the vps and you can now use the SSH key.

**Method 2 (Recommended)**

Step 1: Run the following command nano /root/.ssh/authorized_keys or the directory you placed the file in. This will bring up a text editor.

Step 2: Paste by right clicking the new SSH key into the file and then press CTRL + O to save and the CTRL+X to exit.

Step 3: Run this command: nano /etc/ssh/sshd_config

Step 4: Using the arrow keys, you need to find and change the following details. Replace the line #PubkeyAuthentication yes to PubkeyAuthentication yes.

Step 5: Replace the line #AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2 with the following line: AuthorizedKeysFile %h/.ssh/authorized_keys



Step 6: This is an option step, but first read the warning before continuing. Replace the line #PasswordAuthentication yes with PasswordAuthentication no. This disables logging in with passwords for more security.

Follow the above step with caution, if not done correctly, you will be locked out if closing the session. Test in a new session that the SSH key works before closing any session.

Step 7: For Ubuntu, run this command: systemctl restart ssh and for CentOS, run systemctl restart sshd.

The SSH key has now been setup succesfully, please proceed to our next guide where we will use our downloaded file to login using SSH keys.
Was this article helpful?
Cancel
Thank you!