SSH key connection to VM

SSH key connection to Virtual Machine (VM) #

What is the SSH key for? #

SSH is used to gain secure remote access to the system. Access is achieved by using a key. Your private key must remain on your host, and a public key file (.pub) that is not secret must be copied to the remote system to enable your private key to be used for access.

You must provide us with the public key (.pub) if you want to use key authentication.

SSH key creation and connection on MacOS and Linux OS #

  1. To generate a 2048-bit RSA key pair, run the standard OpenSSH toolset on your computer.
  2. Enter the ssh-keygen command to generate a key.
ssh-keygen
  1. Enter a file in which to save the key. By default, the keys are stored in the ~/.ssh directory with the filenames id_rsa for the private key and id_rsa.pub for the public key.
Using the default locations allows your SSH client to find your SSH keys when authenticating automatically, so we recommend accepting them by pressing ENTER.
  1. Enter the passphrase (empty for no passphrase) and confirm it.
  2. The key has been generated.
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa): 
Created directory '/home/user/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/user/.ssh/id_rsa
Your public key has been saved in /home/user/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:n5atjy1iEhEH+TK/SL73x1YDg0qfmsdVoxhfRUKphyU user@hostname
The key's randomart image is:
+---[RSA 3072]----+
|      .o     .oo.|
|      o .   E o..|
|       +   . = . |
|      + o o = =  |
|       *So = B . |
|      o o.+++ o  |
|     o o ==o.. . |
|      + B.+++    |
|      .= ++=o    |
+----[SHA256]-----+
  1. To get a public key, enter the cat command.
cat ~/.ssh/id_rsa.pub
Example: >ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCloXnzRVi2LQVzJds3xqrmBQPOt8HOKSA8cu+CwtNd8VIfyZt597l9CiFW6eLT4lJHn66Y3nbL1RjlnVQkkav5oD4LsLrB/BTbUtYwdGJRVhy8aRKNjmnFWGkhSxBART0jCbytZPA27ijrDGPJaijW3krPyk11N6byhLqaHaJR5UzSWyr3QDhJRRSBhChYE3VaW/T3pi+IGOxT2kufFn0HNoYXnaQ1rhhmrGX1C3kxO5CLHTPPO00X0+/rB3jZqXZtqme13rPwCghCyysd5w5vojMbd8dBewSl6EjlUj9F6iyQ0CiG2nUzC0aSLgErhmdHN8ecsG03EieSzG26j7fw3LAUT1jKlbGMxLaG/bNfUnMCntEvIvWckj6nnhrW/P0VXKukpjjZiMr+imdud03ghQgrIdXIf1MBcpkKWNpZPaNPnKhObu2RiBB8zcYXIlCoj9UmLlV2AjW82oJ5proE5njXLF1CTBLayYuseU3A079zZ/4Hbx+WBX+ct+Mltqc= user@hostname
  1. To add generated SSH key to myDelska profile, copy the id_rsa.pub public key content to the clipboard.
  • Click on the circle (Users) in the top right corner and select SSH keys.
  • Click Add SSH key and Paste key here.
  • Enter your name and click the Add SSH key.
  • The key will be saved.
  1. The key is saved.

Connect to the VM from your local computer #

Open a terminal and run the command:

ssh root@<IP_address_of_VM>

SSH key creation and connection on Windows OS #

  1. To generate an SSH key, it is necessary to install the client for remote access protocols - PuTTY (putty-64bit-0.80-installer.msi).
  2. Download PuTTY here: https://www.chiark.greenend.org.uk/~sgtatham/putty/, or via the Microsoft Store.
  3. Install it on your computer by following the instructions.
  4. After the installation is complete, open PuTTYgen from the START menu or by pressing Windows + R and typing in the command:
puttygen
  1. Select the ECDSA key type and click Generate. Your unique SSH key has been generated.
  2. The generated SSH key will appear in the textbox. Copy it to your myDelska profile by following the steps:
  • Click on the circle (Users) in the top right corner and select SSH keys.
  • Click Add SSH key and Paste key here.
  • Enter your name and click the Add SSH key.
  • The key will be saved.

When you’re done, click the Save Private Key button and choose a safe place to save the key. Your key can have any name you choose, along with any extension .PPK (PuTTY private key) has automatically been applied.

Use Putty:

  1. Open PuTTY.
  2. Add VM IP address in Session » Host Name (IP Address).
  3. Add Saved Sessions name.
  4. Go to Connection » Data » Auto-login.
  5. Add root username.
  6. Go to Connection » SSH » Auth » Credentials.
  7. In “Private key file for authentication”, click Browse and select your saved .ppk file with the key.
  8. Return to the Session section.
  9. Click Save.
  10. Click Open.