Create and host an SSH key on a dedicated server
SSH keys can be used to securely connect to server via the encrypted SSH protocol. This is a key pair: the private key is stored on the local computer and the public key is hosted on the server.
For authorization on a dedicated Linux server, we recommend using SSH keys instead of login and password.
SSH keys of types rsa, ecdsa, and dsa can be used.
- Create SSH key pair.
- Optional: add public SSH key to SSH key repository.
- Place a public SSH key on the server: c OS reinstallation or without OS reinstallation.
Create SSH keys
- in Linux/MacOS
- in Windows OS
-
Open the CLI.
-
Generate a pair of SSH keys:
ssh-keygen -t rsa
-
A message will appear asking you to select a directory to store the key pair:
Enter file in which to save the key (</home/user/.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 security, repeat the passphrase and press Enter:
Enter passphrase (empty for no passphrase):
Enter the same passphrase again: -
Wait for a message that the keys have been generated. Two files will be created:
id_rsa
(private key) andid_rsa.pub
(public key). The key fingerprint and its image will appear in the terminal: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: -
Print and save the public SSH key:
cat <~/.ssh/id_rsa.pub>
Specify
<~/.ssh/id_rsa.pub>
, which is the full path to the public key that you specified in step 3.
In Windows 10, you can create an SSH key pair via the command line (cmd.exe) just like in Linux/macOS. Earlier versions of Windows use PuTTY for this purpose.
- Install PuTTY and run the PuTTYgen application.
- From the Type of key to generate menu, select the RSA key type.
- Press Generate. Move the cursor within the PuTTYgen window until a key pair is created. Once created, the public key will be displayed on the screen.
- 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.
Add a public SSH key to the repository for SSH keys
The key added to the storage for SSH keys can be placed on the server automatically only when the OS is reinstalled.
- In Control Panel, go to Servers and colocation → SSH keys.
- Click Add SSH Key.
- Enter the name of the key.
- Insert a public SSH key.
- Click Add Key.
Place SSH key on dedicated server with OS reinstallation
-
In Control Panel, go to Servers and colocation.
-
Open the server page → Operating System tab.
-
Click Change OS Configuration
-
In the SSH key field, add the SSH key:
- select the SSH key that you added to the SSH key repository;
- or add a new SSH key that you created earlier. The key will be added to the storage for SSH keys.
-
Click Set.
Place SSH key on dedicated server without OS reinstallation
Without reinstalling the OS, the public SSH key can only be placed on the server by copying the key from the local computer.
- Linux/macOS
- Windows
-
Open the CLI.
-
Copy the public SSH key to the server:
ssh-copy-id -i <~/.ssh/id_rsa.pub> <username>@<ip_address>
Specify:
<~/.ssh/id_rsa.pub>
is the full path to the public key on the local computer;<username>
is the username;<ip_address>
is the public IP address of the server.
-
Enter the user's password.
-
Open cmd.
-
Copy the public SSH key to the server:
scp </path/to/file> <username>@<ip_address></path/to/destination>
Specify:
</path/to/file>
is the full path to the public key on the local computer;<username>
is the username;<ip_address>
is the public IP address of the server;</path/to/destination>
is the path to store the public key on the server.