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).
- Start the PuTTYgen program.
- Select Type of key to generate - SSH-2 RSA.
- Click Generate.
- In the process of creating a key, move the mouse cursor randomly. This is necessary to generate random values in the key structure.
- 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.
- Click Save public key to save the public key.
- Click Save private key to save the private key.
- 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.
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).
- Connect to the server via SSH.
- 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 - Open the file for storing keys:
nano ~/.ssh/authorized_keys
- 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.
- Save your changes to the file.
- 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.
- 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
- Start the terminal. To generate keys, run the command:
ssh-keygen
- 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): - If you press Enter, the key will be saved to the default directory.
- 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
- Run the command:
ssh-copy-id user@server
where user is the login
server - server IP address - The contents of the file with the public key id_rsa.pub will be copied to the ~ / .ssh/authorized_keys file on the server.
- 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.