Connect to Linux VM via SSH

On this page, you can find an explanation of how to connect to the Linux Virual Machine created in the Cloud Console using SSH Protocol

Table of contents

  1. Prerequisites
  2. Configuring Firewalls
  3. Connect using SSH

Prerequisites

In this article, we will assume that we have already created the following resources, that refer to the Project named TestPr, that was created in the Organization named Test1:
  • SSH Key, that was created with the next parameters:
    • Name: testV;
    • Public key is placed on the Linux VM during its creation;
    • Private Key was copied to the clipboard and saved on the local system in the next text file (for example: ~/.ssh/id_rsa).
  • Linux Virtual Machine - that was created with the next parameters and has IP: 185.226.42.34:
    • Name: TestConnection;
    • Flavor: VC-2;
    • Image: ubuntu-server-18.04-LTS-20201111;
    • Key pair: testV;
    • Networks: public;
    • Firewalls: default;
    • Volume size: 10.

For more information on creating and configuring these resources, see the following articles:

Configuring Firewalls

By default, all created Virtual Machines belong to the default Firewall, which allows access to the Internet from the VM, but denies almost all access on the VM from outside, except for objects belonging to the same default Firewall. Thus, using only the default Firewall, we cannot connect to the selected Virtual Machine remotely via SSH.

NOTE:

Default Firewall allows all outbound traffic and controls the inbound traffic that's allowed to reach the VMs that are associated with the default Firewall too. 

To resolve this, we need to add an additional Firewall with a rule that will allow incoming traffic to port 22 on the Virtual Machines and assign this Firewall to the VM too, or just add the required rule to the Firewall that is already assigned to the Virtual Machine. 

To create Firewall with the rule described above do the following:

  • open the Firewalls page - for this you need on the Homepage to select the Security from the VIRTUAL DATACENTER block and click on the Firewalls TAB:

secur

fw2

  • on the Firewalls page click on the CREATE FIREWALL icon in the upper left corner:

con9

  • on the following Create Firewall window come up with the Firewall Name and Description and click on the CREATE button:

con10

  • open the Firewall Rules page - for this you need to click on the Name of the corresponding Firewall:

con11

  • on the Firewall Rules page click on the CREATE FIREWALL RULE icon in the upper left corner:

con3

  • on the following Create Firewall Rule window specify the fields as shown below and click on the CREATE icon:

con5

This newly added rule will allow access to port 22 on the all VMs in the default Firewall over the public Internet, but if you want to allow access only on the one selected VM you need to specify IP of this VM / 32 in the field named Remote IP prefix - example is shown below:

con002

To add this newly created Firewall to our Virtual Machine, do the following:

  • open the Virtual Machines page - for this you need on the Homepage  to select the Virtual Machines from the VIRTUAL DATACENTER block:

virt

  • open the Virtual Machine details page - you need to click on the Name of the corresponding Virtual Machine:

con001

  • open the NETWORKS & SECURITY page of this VM-  click on the NETWORKS & SECURITY TAB:

con13

  • on the opened page click on the ADD FIREWALL icon in the upper left corner:

con14

  • on the following Add firewall window select our newly created firewall and click on the ADD icon:

con15

This is the first option, how we can configure the Firewall for SSH access - by creating a new one with the required rule. But we can just add this rule to the default Firewall that is already assigned to our VM, and these changes will automatically be applied to the VMs. 

NOTE:

You can add and remove rules at any time. Your changes are automatically applied to the VMs that are associated with the corresponding Firewall.

To add required rule to the default Firewall you need to do next:

  • open the Firewalls page - for this you need on the Homepage to select the Security from the VIRTUAL DATACENTER block and click the Firewalls TAB:

secur

fw2

  • open the Firewall Rules page of the default Firewall- for this you need to click on the Name of the corresponding Firewall:

con4

  • on the Firewall Rules page click on the CREATE FIREWALL RULE icon in the upper left corner:

con3

  • on the following Create Firewall Rule window specify the fields as shown below and click on the CREATE icon:

con5

And that's all, this newly created Firewall Rule will be automatically applied to our Virtual Machine.

Connect using SSH

Since we have the public key deployed on our Linux VM, the private key on our local system (for example ~/.ssh/id_rsa) and a Firewall configured to allow incoming traffic on port 22, we can connect to this Virtual Machine remotely from our local server via SSH, just use the next command: 

ssh -i ~/.ssh/id_rsa username@10.111.22.333

NOTE:

Username for VMs created with Ubuntu image will be ubuntu

with Centos image - centos.

Replace username and 10.11.22.333 in the command with your data and specify the appropriate path to your private key. In our example, the command will look like this:

ssh -i ~/.ssh/id_rsa ubuntu@185.226.42.34

After successfully connecting, you can check your internet access and try pinging ventuscloud.com:

con00