---
title: "Create and place an SSH key on a dedicated server"
sidebar_label: "Create and place an SSH key"
sidebar_position: 2
description: "How to create SSH keys and place a public SSH key on a server via the Control panel or CLI"
---

import Formbricks from '@theme/MDXComponents/Formbricks'
import Tabs from '@theme/Tabs'
import TabItem from '@theme/TabItem'
import {TabItemLabel} from '@selectel/docux/components'

# Create and place an SSH key on a dedicated server

SSH keys can be used for secure [server connection](/dedicated/manage/connect-to-server.mdx) over the encrypted SSH protocol. This is a key pair: the private key is stored on your 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 a login and password.

You can use SSH keys of the following types: `ed25519`, `rsa`, `ecdsa`, and `dsa`.

1. [Create an SSH key pair](#create-ssh-key).
2. Optional: [add a public SSH key to the SSH key repository](#add-public-ssh-key-to-ssh-key-repository).
3. Place a public SSH key on the server:

   * [by reinstalling the OS](#place-ssh-key-on-dedicated-server-with-os-reinstallation);
   * [without reinstalling the OS](#place-ssh-key-on-dedicated-server-without-os-reinstallation).

## 1. Create SSH keys \{#create-ssh-key}

<Tabs queryString="create-ssh-key">
  <TabItem value="linux/macOS" default>
    <TabItemLabel>
      Linux/macOS
    </TabItemLabel>

    1. Open the CLI.

    2. Generate an SSH key pair:

       ```bash
       ssh-keygen -t <key_type>
       ```

       Specify `<key_type>` — the SSH key type: `ed25519`, `rsa`, `ecdsa`, or `dsa`.

    3. A message about choosing a directory to store the key pair will appear — an example for an rsa key:

       ```bash
       Enter file in which to save the key (~/.ssh/id_rsa):
       ```

       To keep the default directory for storing keys, press **Enter**. If you want to choose a different directory, specify the full path to it, for example `/home/user/id_rsa`, and press **Enter**.

    4. Optional: enter a passphrase for additional protection, repeat it, and press **Enter**. The passphrase will not be displayed in the command line:

       ```bash
       Enter passphrase (empty for no passphrase):
       Enter same passphrase again:
       ```

    5. Wait for the message confirming that the keys have been generated. Two files will be created: `id_rsa` (private key) and `id_rsa.pub` (public key). The key fingerprint and its randomart image will appear in the terminal:

       ```bash
       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:
       ```

    6. Display the public SSH key:

       ```bash
       cat <path>
       ```

       Specify `<path>` — the full path to the public key you specified in step 3, for example `~/.ssh/id_rsa.pub`.
  </TabItem>

  <TabItem value="windows">
    <TabItemLabel>
      Windows
    </TabItemLabel>

    In Windows 10, you can create an SSH key pair via the command line (`cmd.exe`) just like in Linux or macOS. In earlier versions of Windows, PuTTY is used for this.

    1. Install [PuTTY](https://www.putty.org/).
    2. Open the PuTTYgen application.
    3. In the **Parameters** → **Type of key to generate** field, select the RSA key type.
    4. Click **Generate**.
    5. Move the cursor in the PuTTYgen window until the key pair is created.
    6. After creating the keys, click **Save public key** and **Save private key**.
    7. Specify the path for storing keys.
    8. Optional: in the **Key passphrase** field, enter a passphrase for additional protection.
    9. Copy the public SSH key.
  </TabItem>
</Tabs>

## 2. Optional: add a public SSH key to the SSH key repository \{#add-public-ssh-key-to-ssh-key-repository}

A public SSH key can be added to the SSH key repository and placed on the server automatically when [ordering a new server](/dedicated/order) or [when reinstalling the OS for an existing server](#place-ssh-key-on-dedicated-server-with-os-reinstallation).

1. In the [Control panel](https://my.selectel.ru/servers/ssh), on the top menu, click **Products** and select **Dedicated Servers**.
2. Go to the **SSH Keys** section.
3. Click **Add SSH key**.
4. Enter the key name.
5. Paste the public SSH key.
6. Click **Add**.

## 3. Place an SSH key on a dedicated server \{#place-ssh-key-on-dedicated-server}

You can place a public SSH key:

* [by reinstalling the OS](#place-ssh-key-on-dedicated-server-with-os-reinstallation);
* [without reinstalling the OS](#place-ssh-key-on-dedicated-server-without-os-reinstallation).

### Place an SSH key on a dedicated server by reinstalling the OS \{#place-ssh-key-on-dedicated-server-with-os-reinstallation}

1. In the [Control panel](https://my.selectel.ru/servers), on the top menu, click **Products** and select **Dedicated Servers**.

2. In the **Servers** section, open the **Server list** tab.

3. Open the server page → **Operating System** tab.

4. Click **Reinstall OS**.

5. In the **SSH key** field, add an SSH key:

   * check the box for the required SSH key that you have [added to the SSH key repository](#add-public-ssh-key-to-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 will be added to the SSH key repository.

6. Click **Install**.

### Place an SSH key on a dedicated server without reinstalling the OS \{#place-ssh-key-on-dedicated-server-without-os-reinstallation}

Without reinstalling the OS, a public SSH key can be placed on the server only by copying the key from your local computer. The `ssh-copy-id` command adds a public SSH key to the end of the `~/.ssh/authorized_keys` file. The command creates the directory and file if they do not yet exist.

<Tabs queryString="place-ssh-key">
  <TabItem value="linux/macOS" default>
    <TabItemLabel>
      From Linux/macOS
    </TabItemLabel>

    1. Open the CLI on your local computer.

    2. Copy the public SSH key to the server:

       ```bash
       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>` — the username;
       * `<ip_address>` — the server's public IP address.

    3. Enter the user password.
  </TabItem>

  <TabItem value="windows">
    <TabItemLabel>
      From Windows
    </TabItemLabel>

    1. Open cmd on your local computer.
    2. Copy the public SSH key to the server:

       ```bash
       scp <local_path> <username>@<ip_address>:<server_path>
       ```

       Specify:

       * `<local_path>` — the full path to the public key on your local computer;
       * `<username>` — the username;
       * `<ip_address>` — the server's public IP address;
       * `<server_path>` — the path for storing the public key on the server, for example `C:\Users\username\.ssh\authorized_keys`.
  </TabItem>
</Tabs>

<Formbricks />
