Configuring Authorization by RSA Key

When connecting to the server using the secure SSH protocol, you can use a password or RSA key. An RSA key is considered more preferable (less chance of password interception and more convenient authorization).

To use an RSA key, you must first create it on your local computer and then copy it to the server. The procedure for creating an RSA key differs depending on the operating system.

Windows

Generating an RSA key

To create an RSA key in Windows, you can use a special program PuTTYgen (recommended to download from the official website).

  1. Start the PuTTYgen program.
  2. Select Type of key to generate - SSH-2 RSA.
  3. Click Generate.
    PuTTY Key Generator - Generate
  4. In the process of creating a key, move the mouse cursor randomly. This is necessary to generate random values ​​in the key structure.
  5. After creating a key, you can set a passphrase in the Key passphrase field. This allows you to increase the level of connection security, but each time you have to enter a passphrase when connecting.
  6. Click Save public key to save the public key.
  7. Click Save private key to save the private key.
  8. Save the contents of the Public key for pasting into OpenSSH authorized keys file in a text file. This content is required to copy the key to the server.
    Generating Public key

Copying Keys to the Server

To copy keys to the server, you can use the pageant utility (it is recommended to download from the official site).

  1. Connect to the server via SSH.
  2. Create a directory and file for storing keys on the server:
    mkdir ~/.ssh

    chmod 0700 ~/.ssh

    touch ~/.ssh/authorized_keys

    chmod 0644 ~/.ssh/authorized_keys
  3. Open the file for storing keys:
    nano ~/.ssh/authorized_keys
  4. Paste into the file the text from the Public key for pasting into OpenSSH authorized keys file field, obtained in step 6 of creating keys.
  5. Save your changes to the file.
  6. Run the pageant program. As a result, the program icon will be displayed in the tray. Right click on the icon and click Add Key.
  7. Specify the path to the private key saved at step 5 of key generation. Click Open. Enter the passphrase (if installed).

Linux и MacOS

Generating RSA Keys

  1. Start the terminal. To generate keys, run the command:
    ssh-keygen
  2. As a result, a message will be displayed:
    Generating public/private rsa key pair.

    Enter file in which to save the key (/home/user/.ssh/id_rsa):
  3. If you press Enter, the key will be saved to the default directory.
  4. Set the passphrase. You can press Enter without entering a passphrase. The passphrase will need to be entered with each authorization for this key.

Keys are stored in the ~/.ssh/ directory in files id_rsa (private key) and id_rsa.pub (public key).

Copying keys to the server

  1. Run the command:
    ssh-copy-id user@server
    where user is the login
    server - server IP address
  2. The contents of the file with the public key id_rsa.pub will be copied to the ~ / .ssh/authorized_keys file on the server.
  3. Now you can use the command to connect to the server:
    ssh user@server

If you have any questions, please create a ticket to technical support.