How to Create an SSH Key Pair for Your VPS Server

When you install a VPS Cloud you will be asked to provide your public SSH key from an SSH key pair you have created. An SSH key pair consists of two keys, a public key and a private key. You will create the SSH key pair on your own computer, then you will provide us with the public key. Your computer and the VPS server will then use these two keys to communicate securely.

Creating this key is a necessary step when creating a new VPS server. This process will be different depending on your operating system.

Linux or MacOS

Creating the Key Pair

First, open a terminal and go to your user’s ssh directory.

cd ~ / .ssh

Next, type the following command.

ssh-keygen -t ed25519

When you see the following prompt, type enter to accept the default file name.

Enter file in which to save the key (/home/example/.ssh/id_ed25519):

Next, you will be asked for a password. You can type enter to leave it blank or enter a password for added security. You will then validate the password you chose, either by typing enter to confirm a blank password or by typing the password in a second time.

The system will then generate the public key and the private key and save them in the directory specified. Keep the terminal active for the next step.

Retrieve the Public Key

While still in the terminal, use the following command to view your newly created public key. If you gave the key a name other than default replace “id_ed25519” with the name you chose.

cat id_ed25519.pub

Select all of the displayed content, which usually starts with “ssh-” and ends with your username (for example: example @ example).

You can then paste this key in the appropriate field in the creation screen for a Gandi VPS server.

Configure SSH for Console Login

On most Linux systems, the “config” file updates automatically if you use the default filename. You can check to make sure the keys is present using the cat command as shown in the previous section. Make sure you are in the .ssh directory when you use this command.

If the key is present, you can connect to your server directly by going to the “VPS” section in your account interface and clicking on the name of your server. You can then click on the key underneath “Authentication.”

Windows

Install OpenSSH Windows

On Windows 10, the OpenSSH client is available as an optional feature and therefore may not be enabled on your windows.

To check open Windows settings (the gear (⚙) in the menu), then go to Applications and Features and find the link “Optional features”. If “OpenSSH Client” does not appear, click “Add Feature” to do so.

Note

It is not necessary to also install the “OpenSSH Server”.

Configure OpenSSH

Windows does not create the necessary directories by default, so it may be necessary to do this manually from the file explorer.

First, check if the .ssh directory exists by going to your user directory and looking for an .ssh directory. Since this type of file is hidden by default, you should go to “View” in the file explore and check “Hidden Items.”

If the .ssh directory exists you can move to the next step. If it does not exist, create the .ssh directory.

Create the Key Pair

To start, launch a “Windows Powershell” terminal.

Next, go to the .ssh directory.

cd .ssh

Enter the following command:

ssh-keygen -t ed25519

When you see the following prompt, give your key a name. You name should have no spaces or accented characters. For the purposes of this tutorial, we will use “example_25519” as the file name.

Enter file in which to save the key (/home/example/.ssh/id_ed25519):

Next, you will be asked for a password. You can type enter to leave it blank or enter a password for added security. You will then validate the password you chose, either by typing enter to confirm a blank password or by typing the password in a second time.

The system will then generate the public key and the private key and save them in the directory specified.

You should then open the file (”example_22519” in the above example, or whatever name you chose to give the file) using notepad or another text editor.

Next, copy the public key provided in this file and paste it when prompted during the creation of a VPS.

Configure SSH for connection through the Powershell terminal

You will now need to configure SSH to connect to your new VPS server.

The easiest way is to go through the file explorer and create a new text file named “config” in the .ssh directory.

Add the following lines to this file, but with the following changes:

  • Replace “46.xxx.xxx.xx” with the IP address of your VPS. You can find the IP address by going to VPS in your Gandi account, then clicking on the name of the server.

  • Replace “admin” with the default user (debian or ubuntu)

  • Replace “example_22519” with the file name you gave your key.

Host 46.xxx.xxx.xxx
     User admin
     IdentityFile ~/.ssh/example_25519

Save the file and exit Notepad.

Once your VPS server is created, you can connect via the command displayed in the administration of your VPS. If you have not entered a passphrase, you will not be prompted for a password when connecting.

In Case of “Permission denied (publickey)” Error

You may encounter this error sometimes when trying to login using SSH. This means that your system cannot find the private key that should be stored on your computer. In this case it is necessary to modify or add the “config” file for your user.

To edit this file you can use Nano or VIM through the terminal, or open the file with an external text editor with a graphical interface. The following steps explain how to edit this file using Nano. In principle, we assume that you are still in the “.ssh” directory where you created the key.

First, type this command.

nano config

Add the following lines to this file, but with the following changes:

  • Replace “46.xxx.xxx.xx” with the IP address of your VPS. You can find the IP address by going to VPS in your Gandi account, then clicking on the name of the server.

  • Replace “id_ed22519” with the file name you gave your key.

Host 46.xxx.xxx.xxx
     User admin
     IdentityFile ~/.ssh/id_ed25519

Save the file (CTRL+o in nano) and exit (CTRL+x in nano).

Once your VPS server is created, you can connect via the command displayed in the administration of your VPS. If you have not entered a passphrase, you will not be prompted for a password when connecting.