Create and host an SSH key on a dedicated server
SSH keys can be used to securely connect to a server using the encrypted SSH protocol. It is a pair of keys: the private key is stored on the local computer and the public key is placed on the server.
For authorization on a dedicated Linux server, we recommend using SSH keys instead of login and password.
SSH keys of types ed25519, rsa, ecdsa, and dsa can be used.
-
Place a public SSH key on the server:
1. Create SSH keys
Linux/macOS
Windows
-
Open the CLI.
-
Generate a pair of SSH keys:
ssh-keygen -t <key_type>
Specify
<key_type>
— SSH key type:ed25519
,rsa
,ecdsa
, ordsa
. -
A message will appear asking you to select a directory to store the key pair — example for rsa key:
Enter file in which to save the key (~/.ssh/id_rsa):
To leave the default directory for storing keys, press Enter. If you want to select a different directory, enter it in the format
/path/to/id_rsa
and press Enter. -
Optional: enter a passphrase for additional protection, repeat it, and press Enter. The passphrase will not be displayed on the command line:
Enter passphrase (empty for no passphrase):
Enter same passphrase again: -
Wait for the message that the keys have been generated. Two files will be created:
id_rsa
(private key) andid_rsa.pub
(public key). The terminal will display the key fingerprint and its image:Your identification has been saved in ~/.ssh/id_rsa
Your public key has been saved in ~/.ssh/id_rsa.pub
The key fingerprint is:
The key's randomart image is: -
Output the public SSH key:
cat <path>
Specify
<path>
is the full path to the public key you specified in step 3, for example~/.ssh/id_rsa.pub
.
In Windows 10, you can create an SSH key pair in the command line (cmd.exe) just like in Linux/macOS. In earlier versions of Windows, PuTTY is used for this purpose.
- Install PuTTY.
- Open the PuTTYgen application.
- In the Parameters → Type of key to generate field, select the RSA key type.
- Click Generate.
- Move the cursor in the PuTTYgen window until a key pair is created.
- After creating the keys, click Save public key and Save private key.
- Specify a path to store the keys.
- Optional: in the Key passphrase field, enter a passphrase for additional security.
- Copy the public SSH key.
2. Optional: add a public SSH key to the SSH key repository
A public SSH key can be added to the storage for SSH keys and placed on the server automatically when ordering a new server or when reinstalling the OS for an existing server.
- In the Control Panel, on the top menu, click Products and select Dedicated Servers.
- Go to the SSH keys section.
- Click Add SSH Key.
- Enter the name of the key.
- Insert a public SSH key.
- Click Add.
3. Place the SSH key on a dedicated server
Placing a public SSH key is possible:
Place SSH key on a dedicated server with OS reinstallation
-
In the Control Panel, on the top menu, click Products and select Dedicated Servers.
-
In the Servers section, open the Server List tab.
-
Open the server page → Operating System tab.
-
Click Change OS Configuration.
-
In the SSH key field, add an SSH key:
- check the checkbox with the desired SSH key that you added to the SSH key repository;
- or click Add New Key. Enter a key name and paste the public SSH key you created earlier. Click Add. The key is added to the SSH key repository.
-
Click Install.
Place SSH key on a dedicated server without reinstalling the OS
Without reinstalling the OS, the public SSH key can only be placed on the server by copying the key from the local computer.The ssh-copy-id
command adds the public SSH key to the end of the ~/.ssh/authorized_keys
file . The command creates the directory and file if they are not already created.
From Linux/macOS
From Windows
-
Open the CLI on the local computer.
-
Copy the public SSH key to the server:
ssh-copy-id -i <path> <username>@<ip_address>
Specify:
<path>
— the full path to the public key on the local computer, e.g.~/.ssh/id_rsa.pub
;<username>
— username;<ip_address>
— public IP address of the server.
-
Enter the user's password.
-
Open cmd on the local computer.
-
Copy the public SSH key to the server:
scp <local_path> <username>@<ip_address>:<server_path>
Specify:
<local_path>
— the full path to the public key on the local computer;<username>
— username;<ip_address>
— public IP address of the server;<server_path>
— path for storing the public key on the server, e.g.C:\Users\username\.ssh\authorized_keys
.