> For the complete documentation index, see [llms.txt](https://docs.glesys.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.glesys.com/products/compute/kvm-virtual-machines/how-tos/create-virtual-machines.md).

# Create virtual machines

***

## Create a KVM virtual machine using the control panel

Before creating your virtual machine, verify that you are in the correct [organization](/platform/control-panel/organizations.md) and [project](/platform/control-panel/projects.md). The server will be created for the organization and project you are currently working on.

<div align="left" data-full-width="false"><figure><img src="/files/2HrQYet3DcGjrLsKaoXQ" alt="" width="375"><figcaption></figcaption></figure></div>

In the control panel, navigate to **Compute** → **Virtual machines** and select **Create**. Alternatively, click the plus icon next to **Virtual machines** when hovering the mouse.

### Basic configuration

At the top of the page, select **KVM** as the virtualization solution.

You choose the image for your virtual machine in the **template** dropdown menu. Operating systems include Linux images (like AlmaLinux, Debian, and Ubuntu) and Windows Server.

In the **data center** dropdown menu, select the data center or region where you want to create your virtual machine. A suitable default has been selected for you; however, please choose the data center closest to you and your users to ensure optimal performance and minimal latency.

<div align="left" data-full-width="false"><figure><img src="/files/nma2FicJ9q2b8tcljpwc" alt=""><figcaption></figcaption></figure></div>

### Set a hostname

Next, assign a name to the virtual machine that will be used in the control panel and as the server’s hostname.

<div align="left" data-full-width="false"><figure><img src="/files/nlGBFtrI1tIlZgf0TQjR" alt=""><figcaption></figcaption></figure></div>

#### **How to retrospectively modify the hostname**

Changing the hostname in the control panel later will not automatically update it on the virtual machine. To change the hostname, follow the guide below.

{% tabs %}
{% tab title="Linux" %}
In Linux, change the hostname by utilizing the command `hostnamectl`:

{% code title="Command" %}

```
sudo hostnamectl set-hostname new-name.example.com
```

{% endcode %}

In this example, the hostname is changed to *new-name.example.com*.
{% endtab %}

{% tab title="Windows Server" %}
In Windows, you can change the hostname by going to **Settings** → **System** → **About** and clicking **Rename this PC**.

<div align="left"><figure><img src="/files/kGY86GHYIy5fuIn5krGo" alt="" width="563"><figcaption></figcaption></figure></div>
{% endtab %}
{% endtabs %}

### &#x20;Add users

You also need to create one or more users. These users will be created on the virtual machine's operating system with `sudo` privileges in Linux and administrator rights in Windows. If you need to create regular users without administrator rights, you can add them manually to the VM's operating system later.

You can create multiple users by clicking **Add user**.

<div align="left"><figure><img src="/files/zfKKdwU7os489QZvkV5V" alt="Image showing how to add users in the UI"><figcaption></figcaption></figure></div>

Please note that the SSH key field is displayed only for Linux servers.

#### **Linux servers and SSH keys**

When creating users for a Linux system, you can provide them with an SSH key and a password. If you select both a key and a password, the user can log in over SSH using their key; however, password-based SSH login will be disabled as a security measure. However, the password can still be used to log in via the console in the control panel in case the user accidentally locks themselves out. With a password, the user must also enter it when using `sudo`. Without a password, the user can run `sudo` without any authentication.

Be aware that if any user lacks an SSH key, all users can log in via SSH using their password. This situation could present a security risk, as passwords are generally less secure than SSH keys.

You can save your SSH keys for the current project by clicking the **SSH keys** dropdown menu and selecting **Add SSH key**. The next time a new VM is created, you can choose the key directly from the dropdown menu.\
\
If you need to modify or delete a key, click **Manage SSH keys** in the same dropdown menu. In the image below, a saved key named *glesys* is shown.

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

It's also possible to manage your SSH keys using the [**SSH keys**](/products/compute/manage-ssh-keys.md) menu option in the left-hand menu.

#### **Windows Server and SSH keys**

You can't use SSH keys in Windows; otherwise, you create usernames and passwords as you do for Linux.

### Provide user data with cloud-config (optional)

With cloud-config, you can automate the creation of new VMs, enabling more customization options than those available in the control panel. For example, you can install specific packages and change configuration files in the operating system. This occurs when the VM starts for the first time.

Click on **Cloud config** to expand the view.

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

Cloud-config is especially useful when creating multiple VMs with similar configurations. For example, suppose you need to create a dozen web servers for a project. In that case, you can create a cloud-config that automatically installs Apache, creates a webpage, starts Apache, and opens the firewall.

The commands included in the cloud-config are typically executed only during the system's initial startup. However, they can be executed again if needed.

{% tabs %}
{% tab title="Debian and Ubuntu" %}
When creating a Debian or Ubuntu server, paste the following snippet into the Cloud Config text field as an example. This will install the following packages: `vim`, `tmux`, and `apache2`. A simple webpage will also be created with the content specified under `content`. Modify it to suit your needs.

```yaml
## template: glesys
#cloud-config
{{> users }}
package_update: true
packages:
  - apache2
  - tmux
  - vim
write_files:
  - path: /var/www/html/index.html
    permissions: '0644'
    owner: 'root:root'
    content: |
      <!DOCTYPE html>
      <html lang="en">
      <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>My very own webpage</title>
      </head>
      <body>
        <h1>My very own webpage</h1>
      </body>
      </html>
```

#### **Verify the configuration**

Now, you can try accessing the server's IP address in a web browser once it has started. You should see the text "My very own webpage."

You can verify that cloud-init executed the configuration file by reviewing the log files `/var/log/cloud-init.log` and `/var/log/cloud-init-output.log`. The second log file shows the output produced by the commands when executed.

Reviewing the files in the directory `/var/lib/cloud` is also possible. This includes, among other things, the complete cloud-config file that was executed, along with the expanded sections for `{{> users}}`.

#### **Important note**

Note that the first three lines of the text you pasted were the same as the pre-filled example when you expanded the cloud config section. These three lines are necessary. The lines `## template: glesys` and `{{> users }}` are required to create users, add passwords, and generate SSH keys. The line `#cloud-config` indicates to `cloud-init` that the text should be interpreted as cloud-config.

If, for some reason, you need to rerun cloud-init, this is possible. However, remember that files may be overwritten, such as `index.html` in our example. To rerun the cloud-config, execute the following:

{% code title="Command" %}

```
sudo cloud-init clean
```

{% endcode %}

Cloud-init will execute all the commands again at the next server restart.
{% endtab %}

{% tab title="AlmaLinux and Fedora" %}
If you create an AlmaLinux server, paste the following snippet into the Cloud Config text field as an example. This will install the following packages: `vim`, `tmux`, and `httpd` (Apache2). A simple webpage will also be created. Additionally, Apache2 will be started, and the firewall will be configured to allow web traffic. Modify it to suit your needs.

```yaml
## template: glesys
#cloud-config
{{> users }}
package_update: true
packages:
  - httpd
  - tmux
  - vim
write_files:
  - path: /var/www/html/index.html
    permissions: '0644'
    owner: 'root:root'
    content: |
      <!DOCTYPE html>
      <html lang="en">
      <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>My very own webpage</title>
      </head>
      <body>
        <h1>My very own webpage</h1>
      </body>
      </html>
runcmd:
  - [ systemctl, enable, httpd.service ]
  - [ systemctl, start, httpd.service ]
  - [ firewall-cmd, --add-service=http, --permanent ]
  - [ firewall-cmd, --reload ]
```

#### **Verify the configuration**

Now, you can try accessing the server's IP address in a web browser once it has started. You should see the text "My very own webpage."

You can verify that cloud-init executed the configuration file by reviewing the log files `/var/log/cloud-init.log` and `/var/log/cloud-init-output.log`. The second log file shows the output produced by the commands when executed.

Reviewing the files in the directory `/var/lib/cloud` is also possible. This includes, among other things, the complete cloud-config file that was executed, along with the expanded sections for `{{> users}}`.

#### **Important note**

Note that the first three lines of the text you pasted were the same as the pre-filled example when you expanded the cloud config section. These three lines are necessary. The lines `## template: glesys` and `{{> users }}` are required to create users, add passwords, and generate SSH keys. The line `#cloud-config` indicates to `cloud-init` that the text should be interpreted as cloud-config.

If, for some reason, you need to rerun cloud-init, this is possible. However, remember that files may be overwritten, such as `index.html` in our example. To rerun the cloud-config, execute the following:

{% code title="Command" %}

```
sudo cloud-init clean
```

{% endcode %}

Cloud-init will execute all the commands again at the next server restart.
{% endtab %}

{% tab title="Windows Server" %}
Cloud-config also works for Windows Server and uses the same syntax. An example of a cloud-config for Windows is shown here. Note that we use `{{> windowsUsers }}` in the template instead of `{{> users }}` as we do for Linux.

In the example below, the text “*Hello world”* will be written to the file `C:\test.txt`. After that, the NTP server in Windows will be changed to `gbg1.ntp.netnod.se`.

Finally, we will run the `echo` command, writing the text *"hello"* to `C:\output1.txt`.

```yaml
## template: glesys
#cloud-config
{{> windowsUsers }}
write_files:
   content: Hello world
   path: C:\test.txt
ntp:
  enabled: True
  servers: ['gbg1.ntp.netnod.se']
runcmd:
  - 'echo "hello" > C:\output1.txt'
```

{% endtab %}
{% endtabs %}

### Choose IP addresses

This step involves selecting an IPv4 and IPv6 address for the server. Choose from the available IP addresses in the dropdown menus. You also have the option to select 'No IPv4' or 'No IPv6.' Note that if you have previously reserved one or more IP addresses, they will be listed at the top of the dropdown menu under *Reserved IP addresses*.

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

It is possible to add more IP addresses to the server later; however, you will need to configure them manually within the server's operating system. Learn how to do this in the [Manage servers](/products/compute/kvm-virtual-machines/how-tos/manage-virtual-machines.md#add-or-remove-ip-addresses) section.

### Enable backups (optional but recommended)

You can enable automatic backups of your virtual server. This adds a cost to the server’s price depending on the frequency of the backups.

Here, you can select **Daily Backups** or **Weekly Backups**. Adjust the sliders to manage the number of backups to be retained. In the example below, seven daily and four weekly backups are saved. The backup schedule can be modified later if needed.

The backups are complete disk images of the virtual machine. These images can be used to create new VMs in the exact state the server was in when the backup was made.

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

It is also possible to create manual backups independently of the automatic backups.

### Choose resources

The final step is to choose the amount of resources you want the virtual machine to have. As you adjust the sliders, the server's price is updated.

These resources can be reconfigured later without requiring a server restart. However, note that disk space is an exception; it can be increased later but not decreased. Other resources can be increased or decreased afterward.

When you are satisfied with all the server configurations, click **Create Server**. Normally, it takes only a few seconds for the new server to become ready.

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

## Create VMs using the API

Use the [server/create](https://github.com/GleSYS/API-docs/wiki/API-Documentation#servercreate) endpoint to create a VM using the [API](/platform/control-panel/api.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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.glesys.com/products/compute/kvm-virtual-machines/how-tos/create-virtual-machines.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.
