Cloud-init directives
Cloud-init is an industry-standard tool for automating the initialization of cloud Virtual Machines. It runs on first boot, processes the YAML document in the User Data field, and supports all major Linux distributions. Every document must begin with #cloud-config on the first line.
Set a password
By default, Gcore Virtual Machines do not allow SSH authentication with a username and password — only SSH key authentication is enabled. Setssh_pwauth: True to allow password access.
password— sets the password for the default OS user (e.g.ubuntuon Ubuntu images).chpasswd: { expire: False }— keeps the password active without requiring a change on first login.ssh_pwauth: True— enables password-based SSH authentication.power_state— reboots the VM after cloud-init finishes so the changes take effect.
Create a user
Add ausers block to create a new OS user at boot. The example below creates a guest user with sudo access.
sudo: ALL=(ALL) NOPASSWD:ALL— grants the user passwordless sudo rights.passwd— SHA-512 encrypted password. Generate it withmkpasswd -m sha512crypt guest.groups— comma-separated list of groups. The groups must already exist on the system.lock_passwd: false— allows password-based login.shell: /bin/bash— sets the default shell.
Run
groups after connecting to verify group membership.Enable root user
Configure user groups
Add thegroups directive to create custom groups at boot.
compgen -g to verify the group appears.
Add an SSH key
Add public SSH keys from other machines usingssh_authorized_keys.
cat ~/.ssh/authorized_keys.
Add repositories and install packages
Install packages at first boot using thepackages directive. Packages from external repositories require an apt.sources entry.
Write files
Create files on the VM at boot using thewrite_files directive.
Configure network interfaces
Add a static IP address by writing a Netplan configuration file. Cloud-init merges it with the auto-generated50-cloud-init.yaml during boot.
ip a to verify the static addresses appear on the enp3s0 interface.
Check cloud-init logs
Two log files are available on the VM for diagnosing cloud-init issues./var/log/cloud-init.log — full process log with debug output:
/var/log/cloud-init-output.log — stdout/stderr from scripts cloud-init ran: