Create and place an SSH key on a cloud server
SSH keys can be used for secure server connection via an encrypted SSH protocol. This is a pair of keys: the private key is stored on your local computer, and the public key is placed on the server.
We recommend using SSH keys instead of a login and password for authorization on a cloud server.
You can use SSH keys of the types ed25519, rsa, ecdsa, and dsa. Learn more about SSH keys for users.
-
Optional: add a public SSH key to your user profile.
1. Create an SSH key pair
You can create SSH keys in two ways:
- via the OS;
- using the OpenStack CLI.
Create an SSH key pair via the OS
Linux/macOS
Windows
-
Open the CLI.
-
Generate an SSH key pair:
ssh-keygen -t <key_type>Specify
<key_type>— the SSH key type:ed25519,rsa,ecdsaordsa -
A message about choosing the directory to store the key pair in will appear — an example for an RSA key:
Enter file in which to save the key (~/.ssh/id_rsa):To leave the directory for storing keys set to default, press Enter. If you want to select another directory, enter it in the format
/path/to/id_rsaand press Enter. -
Optional: enter a passphrase for additional protection, repeat it, and press Enter:
Enter passphrase (empty for no passphrase):Enter same passphrase again: -
Wait for the message confirming 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_rsaYour public key has been saved in ~/.ssh/id_rsa.pubThe key fingerprint is:The key's randomart image is: -
Output the public SSH key:
cat <path>Specify
<path>— the full path to the public key you specified in step 3, for example~/.ssh/id_rsa.pub.
Create an SSH key pair via OpenStack CLI
The SSH key will be available only for the single service user, project, and pool for which you configured authorization in the OpenStack API.
When generating SSH keys via the OpenStack CLI, the public key is automatically added to the user profile.
-
Generate an SSH key pair:
openstack keypair create <key_name> --private-key <file_for_key>Specify:
<key_name>— the key name;<file_for_key>— the file where the private SSH key will be saved on your local computer.
2. Optional: add a public SSH key to the user profile
A public SSH key can be added to your own profile or to another user's profile. You can then place the key on the server when creating or on an existing server.
The key will be available in all projects to which the user has been added.
If you generated the SSH key pair via the OpenStack CLI, the public key was automatically added to the user profile.
To your profile
To another user's profile
-
In the control panel, in the upper right corner, open the menu (account number) and select Profile.
-
Go to the Access section.
-
Open the SSH keys tab.
-
Click Add key.
-
Enter the key name.
-
Paste the public SSH key in OpenSSH format.
-
Click Add.
3. Place a public SSH key on a cloud server
You can place a public SSH key when creating a cloud server or on an existing server.
To access a cloud server via SSH, you need to add a public SSH key to the ~/.ssh/authorized_keys file on the server. You can add multiple keys, for example, if you need access for multiple users.
You can place public SSH keys on an existing server using a utility or manually.
Using a utility
Manually
The utility adds the public SSH key to the end of the ~/.ssh/authorized_keys file. The command used creates the directory and file if they do not exist yet.
From Linux/macOS
From Windows
-
Open the CLI on your local computer.
-
Copy the public SSH key to the cloud server:
ssh-copy-id -i <path> <username>@<ip_address>Specify:
<path>— the full path to the public key on your local computer, for example~/.ssh/id_rsa.pub;<username>— user name;<ip_address>— the server's public IP address.
-
Enter the user password.