# Access a Virtual Machine

## Background Information

After creating virtual machine instances, you need to remote control and manage them. Several remote access methods are listed below.

* **RDP (Remote Desktop Protocol)**\
  RDP is a remote desktop protocol commonly used for remote management of Windows operating systems.\
  You're recommended to remote connect to a Windows virtual machine via RDP.
* **SSH (Secure Shell)**\
  SSH is a command-line based remote management tool that uses a secure network protocol. SSH is widely used in UNIX-like operating systems, including Linux, BSD, and macOS.\
  You're recommended to use Terminal or Windows PowerShell to establish an SSH connection to non-Windows virtual machines.
* **RFB (Remote FrameBuffer)**\
  RFB is a protocol used for graphical remote management. VNC (Virtual Network Computing) is a common remote graphical management tool based on the RFB protocol used in UNIX-like operating systems. VNC login provides a graphical desktop environment, allowing you to interact with the virtual machine visually. VNC protocol is also widely supported across multiple operating systems and platforms, which is more flexible and compatible.\
  You're recommended to remotely access and control the graphical interface of your virtual machines via VNC.

These protocols and tools offer various ways to remotely access and manage virtual machines. RDP provides a graphical interface for Windows virtual machines; SSH offers a command-line interface for remote management of UNIX-like virtual machines, and VNC enables graphical remote management of virtual machines regardless of operating systems.

Here we take a Linux VM (`CentOS-1vcpu-2gb-HKG-1`) and a Windows VM (`Windows-1vcpu-2gb-IAD-1`) as examples to demonstrate how to remote access them using you local computer.

* `CentOS-1vcpu-2gb-HKG-1`\
  Default username: `root`\
  Password: `Test+123`
* `Windows-1vcpu-2gb-IAD-1`\
  Default username: `Administrator`\
  Password: `Test+123`

<div align="left"><figure><img src="/files/okyhgfwbfjD21WF9yGd3" alt=""><figcaption></figcaption></figure></div>

{% hint style="info" %} <mark style="color:blue;">**Note**</mark>

* <mark style="color:blue;">See</mark> [<mark style="color:purple;">**Create an Instance**</mark>](/welcome/virtual-machine/get-started/virtual-machine-instance/create-an-instance.md) <mark style="color:blue;">for detailed information about how to create a virtual machine instance.</mark>
* <mark style="color:blue;">Your virtual machine will be associated with one security group at least while being created. To remote access successfully, please ensure the security group allows traffic on the following ports: TCP 22 ( for SSH), TCP 3389 (for RDP), and ICMP port (used for network management and debugging).</mark>
* <mark style="color:blue;">The steps below may vary depending on the operating system and applications you are using. You may need to use different commands or tools to perform the same actions.</mark>
  {% endhint %}

## Access a Linux Virtual Machine via SSH

When you need to access a Linux virtual machine, you can use SSH. Assume a macOS Terminal and a Windows PowerShell.

If you have deployed the SSH public key to your server, you can also using the SSH key for authentication without entering a password.

{% tabs %}
{% tab title="macOS client (Terminal)" %}

#### Prerequisites

* Ensure the virtual machine has SSH enabled and is running.
* Obtain the public IP address of the virtual machine you want to access, that is a Linux VM (`CentOS-1vcpu-2gb-HKG-1`). You can find this information in the instance list page on zenConsole. Here is `128.1.97.230`.

#### Procedures

1. Open the **Terminal** application on your macOS computer. You can find it in the **Applications** > **Utilities** folder, or you can use **Spotlight** to search for it.
2. In the **Terminal**, use the SSH command along with the IP address of the virtual machine to establish a remote connection. The command syntax is as follows:

   ```bash
   ssh root@128.1.97.230
   ```
3. Press **Enter**, and **Terminal** will attempt to establish an SSH connection to the virtual machine. If this is your first time connecting to the VM, you may be prompted to confirm the authenticity of the host by verifying its key fingerprint. Type `yes` to proceed.
4. After the SSH connection is successfully established, you will be prompted to enter the password for the selected username on the virtual machine. Here provide `Test+123` and press **Enter**.
5. Once authenticated, you will have a **Terminal** session open on your macOS computer, but with the remote virtual machine's command-line interface. From here, you can execute commands and perform administrative tasks on the virtual machine.
   {% endtab %}

{% tab title="Windows command line (PowerShell)" %}

#### Prerequisites

* Ensure that the virtual machine has PowerShell Remoting enabled and is running. PowerShell Remoting is available by default on Windows operating systems.
* Obtain the public IP address of the virtual machine you want to access, that is a Linux VM (`CentOS-1vcpu-2gb-HKG-1`). You can find this information in the instance list page on zenConsole. Here is `128.1.97.230`.

#### Procedures

1. Open the Windows **PowerShell** application on your Windows computer. You can do this by searching for "**PowerShell**" in the **Start** menu or by pressing `Win + X` and selecting **Windows PowerShell** or **Windows PowerShell (Admin)**.
2. In the **PowerShell** console, use the following command to establish a remote session with the virtual machine:

   ```bash
   Enter-PSSession -ComputerName 128.1.97.230 -Credential root
   ```
3. Press **Enter**, and you will be prompted to enter the password for the selected username on the virtual machine. Here provide `Test+123` and press **Enter**.
4. Once authenticated, you will have a **PowerShell** session open on your local computer, but with the remote virtual machine's command-line interface. From here, you can execute **PowerShell** commands and perform administrative tasks on the virtual machine.
   {% endtab %}

{% tab title="SSH Key Pair" %}

#### Prerequisites

Obtain the public IP address of the virtual machine you want to access, that is a Linux VM (`CentOS-1vcpu-2gb-HKG-1`). You can find this information in the instance list page on zenConsole. Here is `128.1.97.230`.

#### Procedures

1. Generate an SSH key pair by running the following command on your local computer:

   ```bash
   ssh-keygen -t rsa -b 4096
   ```

   This will generate a 4096-bit RSA key pair, including a private key and a public key. By default, they will be saved in the `~/.ssh` directory.
2. Use the following command to retrieve the generated public key:

   ```bash
   cat ~/.ssh/id_rsa.pub
   ```

   This will display your public key. Copy it.

   <div data-gb-custom-block data-tag="hint" data-style="info" class="hint hint-info"><p><mark style="color:blue;"><strong>Note</strong></mark></p><p><mark style="color:blue;">For Windows operating system, use the <code>type</code> command to display the public key in the Command Prompt or PowerShell:</mark></p><pre class="language-bash"><code class="lang-bash">type %userprofile%\.ssh\id_rsa.pub
   </code></pre></div>
3. Use the SSH command along with the IP address to access the virtual machine:

   ```bash
   ssh root@128.1.97.230
   ```
4. Press **Enter**. This will attempt to establish an SSH connection to the virtual machine. If this is your first time connecting to the VM, you may be prompted to confirm the authenticity of the host by verifying its key fingerprint. Type `yes` to proceed.
5. After the SSH connection is successfully established, you will be prompted to enter the password for the selected username on the virtual machine. Here provide `Test+123` and press **Enter**.
6. On the virtual machine, open the `~/.ssh/authorized_keys` file (create it if it doesn't exist). You can open the file using the following command:

   ```bash
   nano ~/.ssh/authorized_keys
   ```

   Paste the previously retrieved public key into the file and save it.

#### Result

You can now access the virtual machine using the SSH key pair. Run the following command:

```bash
ssh -i ~/.ssh/id_rsa root@128.1.97.230
```

This will authenticate using the private key without requiring a password.
{% endtab %}
{% endtabs %}

## Access a Windows Virtual Machine via RDP

When you need to access a Windows virtual machine, you're recommended to use RDP.

### Prerequisites

* Ensure that the Windows virtual machine is running and has RDP enabled. RDP is available by default on Windows operating systems.
* Obtain the public IP address of the virtual machine, that is a Windows VM (`Windows-1vcpu-2gb-IAD-1`). You can find this information in the instance list page on zenConsole. Here is `98.96.218.54`.

### Procedures

1. Open the **Remote Desktop** client application on your local computer. This application is built into Windows, and you can find it by searching for "**Remote Desktop**" in the **Start** menu.
2. In the **Remote Desktop** client, enter the public IP address, that is `98.96.218.54`, of the virtual machine in the "**Computer**" field.
3. Click **Connect** to initiate the connection.
4. If prompted, enter the credentials for the user account on the virtual machine.\
   \- Default username: `Administrator`\
   \- Password: `Test+123`
5. Once authenticated, the **Remote Desktop** client will establish a connection to the Windows virtual machine. You will see the virtual machine's desktop displayed on your local computer.
6. You can now interact with the Windows virtual machine as if you were sitting in front of it. You can run applications, access files, configure settings, and perform any other tasks you would normally do on a Windows desktop.

Remember to ensure that the necessary firewall rules are configured on both the virtual machine and your local machine to allow RDP connections.

## Access a Linux Virtual Machine via VNC

You can remote access a Linux virtual machine via VNC.

### Prerequisites

You can remote access any virtual machine vis VNC on zenConsole. Please obtain the public IP address of the virtual machine you want to access before remote access. Here we take the Linux VM (`CentOS-1vcpu-2gb-HKG-1`) as an example.

* Default username: `root`
* Password: `Test+123`

### Procedures

1. Go to virtual machine instance list page and click `CentOS-1vcpu-2gb-HKG-1` to enter **Detail** page.

   <div align="left"><figure><img src="/files/8ll9jZu19J6aJeIgqXtv" alt="" width="563"><figcaption><p>Detail Page</p></figcaption></figure></div>
2. Click **VNC Access** to enter VNC access interface. Wait until it shows:

   ```bash
   Connected (encrypted) to: QEMU (instance-xxxxxxxx)
   ```

   Enter the default username: `root`, and press **Enter**

   <div align="left"><figure><img src="/files/JIVa6nkrXFA1Oy3xyobE" alt=""><figcaption><p>VNC Access</p></figcaption></figure></div>
3. Press **Enter**, and **Terminal** will attempt to establish an SSH connection
4. Enter the password for the virtual machine. Here provide `Test+123` and press **Enter**.
5. Once authenticated, the VNC will establish a connection to the virtual machine. You should see the VM's desktop or graphical interface displayed in the VNC client window.
6. *<mark style="color:green;">(optional)</mark>* You can paste your code on the **Clipboard** and click **Run** to quick run your command.

## Access a Windows Virtual Machine via VNC

You can remote access a Windows virtual machine via VNC.

### Prerequisites

You can remote access any virtual machine vis VNC on zenConsole. Please obtain the public IP address of the virtual machine you want to access before remote access. Here we take the Windows VM (`Windows-4vCPU-16gb-HKG-A-1`) as an example.

### Procedures

1. Go to virtual machine instance list page and click `Windows-4vCPU-16gb-HKG-A-1` to enter **Detail** page.

   <figure><img src="/files/N0QHGBUpFEliHZwPKU5q" alt=""><figcaption><p>VNC Access</p></figcaption></figure>
2. Click **VNC Access** to enter VNC access interface. Wait until it shows:

   ```bash
   Connected (encrypted) to: QEMU (instance-xxxxxxxx)
   ```
3. Go to **Keyboard Shortcuts** > **Ctrl+Alt+Del**.

   <div align="left"><figure><img src="/files/NroLgmetpSLt7S6CzFDf" alt=""><figcaption></figcaption></figure></div>
4. Find your password in your email box. Click **Clipboard**, enter the password and click **Run**.

   <div align="left"><figure><img src="/files/eoTe93KB6TJgXV7AiiQN" alt="" width="563"><figcaption></figcaption></figure></div>

## Summary

The protocols and access methods mentioned above provide convenience and flexibility in different scenarios. You can choose the way that best suits your needs to remotely access and manage your virtual machines, whether it's using a graphical user interface or a command-line interface.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.console.zenlayer.com/welcome/virtual-machine/best-practice/access-a-virtual-machine.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
