SSH. Connect to Instance via SSH

You can connect to an Instance using a pair of SSH keys or a password. We tell you in detail about each method.

The SSH protocol (also referred to as Secure Shell) is a method for secure remote login from one server to another. To connect via SSH, make sure that all the necessary rules for incoming traffic are in the firewall settings set.

Please note: you cannot connect to Windows instances via SSH. But you can connect to them via RDP protocol or from the console in Control Panel. With the rest of the machines, you can establish a connection via SSH or from your Control Panel.

Connecting using a pair of SSH keys. Preparation

Connecting using a password. Preparation

Connecting via SHH

Connecting using a pair of SSH keys. Preparation

To connect to an instance, create a public key that will be stored on your instance and a private key that will be placed on your local storage. 

SSH keys generation (Windows 7/8) 

! SSH key generation using the command line interface (cmd) is not available for Windows 7/8 operating systems. 

1. To generate key pairs, use the PuTTY and PuTTYgen apps. 

2. Download and install the PuTTY package. 

3. Launch the PuTTYgen app.

4. In the Type of key to generate field, specify the RSA.

5. And for the Number of bits in a generated key field, set the value to 2048.

6. Click Generate. 

putty_gen.png

Important! During the key generation, move the cursor in the Key field until the key appears in the field. ___________.png

7. In the Key passphrase field, enter a password. 

8. Confirm the password in the Confrm passphrase field.

9. Click Save private key and save the private key.

Attention! Never pass your private key and password to third parties.

10. Click Save public key and save the public key on your local storage. 

11. You can always open and copy the saved key with the Notepad app. 

 notepad.png

 SSH keys generation (Windows 10, Linux OS, Mac OS)

1. To generate keys on Linux/MacOS/Windows 10:

2. Open the console, terminal (MacOS), or command line (cmd.exe fro Windows OS). 

3. Run the command: ssh-keygen -t rsa -b 2048 

4. Enter the key name in the Enter file in which the key should be saved field.

Attention! If you do not specify a directory (for example, .ssh/), the keys are saved in~. /<key name> (for Linux/MacOS) or in C:Users<user_name><key name> (for Windows 10).

5. Press Enter.

6. Then enter the password for the key or leave the field empty and press Enter if you want to create a key without a password.  ______________________.png7. Confirm the password or leave the field empty and press Enter to save the key without a password.  

8. The key was created in the default directory or in the one you specified. 

____________.png9. The public part of the key will be saved in the <key_name>.pub file. Use it to add it to an instance. You can open the ssh key file in text format for copying in the Notepad app.

 SSH keys generation in the personal account 

To create an ssh key from your personal account, follow the steps below.

1. In the G-Core Labs Cloud control panel, go to SSH Keys.

2. Click Autogenerate SSH key.

autogenetae.png3. Enter the key name and click Create SSH key.

________________________.png
Important! Only Latin characters, underscores, spaces, and dots can be used. The length must be between 3 and 63 characters. 

4. The key will be generated and displayed in the list of ssh keys, its public part will already be stored in the system, and the private key will be downloaded to your local storage. 

5. To view the private key, find it in your local storage and open it using the Notepad app.  

How to add SSH keys to your G-Core Labs Cloud personal account 

To add an already created SSH key to your personal account:

1.  In the G-Core Labs Cloud control panel, go to SSH Keys.

2. Click Add SSH key.

add_a_ssh.png

3. In the SSH key Content field, insert the public part of the SSH key.

4. Enter the key name in the Name field.

add_an_ssh_2.png

5. Click Add SSH key.

6. The key will appear in the list of SSH keys.

How to delete SSH keys in your G-Core Labs Cloud personal account 

1. Select the SSH key you want to delete.

2. Click on the three-point sign. 

3. Select Delete.

ssh_delete.png

How to generate and add SSH keys when creating an instance 

In your personal account, you can create and add an SSH key when creating an instance.

When creating an instance, in the SSH key section, you will be asked to add a key that is already stored in your personal account by selecting it from the drop-down list, add n already generated key stored in your local storage, or generate a new key here.

 _________________________________.png

1. When you click Add SHH key, a dialog box opens. Add the public part of the SSH key, enter the key name to identify it in our system, and save it.

______________.png

Next, select a key from the drop-down list to add it to the instance. 

 2. When you click Autogenerate SSH key, a dialog box opens. Enter the key Name to identify it in the system.

autogenerate_2.png

The key will be automatically added to the instance. 

 After adding or generating a new SSH key, the keys will appear in the SSH Keys section.

 ___________ssh_____.png

Connecting using a password. Preparation

Configuring a password

To connect using a password, configure it while creating an instance. In Additional options click on "User data". This will open a field, where you can enter the script that will be processed by a cloud-init agent running on an instance. 

13.png
Paste the code below with the password chosen by you:

#cloud-config
password: your password
chpasswd: { expire: False }
ssh_pwauth: True

Using the specified password you will be able to connect to the instance via SSH or from your Control Panel.

It is not necessary to specify the password explicitly, you can enter its hash (the same password, only in a converted form; the system will be able to read it, but for a person, it looks like a random set of symbols). Then, even if someone gets into the system, he or she won’t know the password — only the hash will be stored inside. And the system will open its doors only to the user who knows the password. To generate a hash, you can use the Python script:

#!/usr/bin/env python3
# based on https://stackoverflow.com/a/17992126/117471
# pip3 install passlib
import sys
from getpass import getpass
from passlib.hash import sha512_crypt
passwd = input() if not sys.stdin.isatty() else getpass()
print(sha512_crypt.hash(passwd , rounds = 5000 ))

Connecting via SSH

Connecting from Windows 7/8

!Connecting to an instance over ssh using the command line (cmd) is not available on Windows 7/8 operating systems. 

To connect, use the PuTTY app.

1. Download and run the PuTTY app. 

2. Go to the Session section, in the Host Name (or IP address) field enter the instance's IP address. You can find the IP address in the IP address column on the Instances page. 

____________________________.png

Important! If you create an instance with only a private address, add a floating IP. To do this, in the Instances section click on the name of the VM. In the window that opens, click Add an IP. For more information about creating floating IP addresses, see the article Networks, subnets, floating IP, firewalls.       

add_ip_float.png

3. In the Port field, set 22 port which is the standard port for SSH connection. 

4. Next, set the Connection type field to SSH.

5. (Step for connecting using a pair of SSH keys only) on the right side of the screen, go to Connection - > SSH -> Auth.

6. (Step for connecting using a pair of SSH keys only) click Browse.

 browse.png

7. (Step for connecting using a pair of SSH keys only) select the file with the private key for the instance in .ppk format.

Important! If your private key is saved in .pem format, convert it to .ppk format following the instructions.

8. Click Open. The console will open.

 login_as.png
9. In the "login" field, enter the user name that was given when creating the instance. You can find it in the instance's tab, you will see is an inscription of the “[login]@[IP of the instance]” type. Most often, the login coincides with the name of the OS. For example, for the instance below it is "ubuntu".


10. (Step for connecting using a pair of SSH keys only) enter the password you configured while creating an instance.


11. Press Enter.  

12. You have connected to your instance.

Connecting from Windows 10, Linux OS, Mac OS 

Attention! If you use Linux OS or Mac OS, go to step 7. 

Windows 10 has a built-in OpenSSH client that allows you to access the server via the console, like on Linux OS. By default, this component is not activated. 

Follow the steps below to activate it.

1. Open Settings.

SETTINGS.png

2. Go to the Apps section and click Optional features.

OPTIONAL_FEATURES.png

3. Find OpenSSH Client and click to expand the detailed description. 

instal_open_sssh.png

4. Click Install.

5. Wait for the installation to be completed. After SSHClient is installed, restart your computer to apply the settings correctly. SSH utility will become available for cmd.

6. Open the command prompt and enter the command with your own values:

"ssh username@192.168.1.92 " — to connect using a password;

"ssh username@192.168.1.92 -i "C:Usersusername.sshid_rsa" — to connect using a pair of SHH keys.

username

Your username, you can find it to the right of "Access to Console" button

192.168.1.92 

Floating IP address of your instance.

Important! If you created an instance with only a private interface, create a floating IP and use it when connecting to the instance over ssh.

C:Usersusername.sshid_rsa

The path to the private key file on your computer.

The key must be in PEM format. 

7. The utility will suggest adding the device to the list of known devices, write yes to add, no to not add. Press Enter.

yes.png

8. (Step for connecting using a password only) enter the password you configured while creating an instance.

9. You have connected to your instance.

Was this article helpful?
Recently viewed articles