Skip to main content

How to Set a Root Password When Creating a Linux Instance in mCloud - Knowledgebase / mCloud - Micron21 Knowledge Hub

How to Set a Root Password When Creating a Linux Instance in mCloud

Authors list

Purpose

This guide explains how to set an initial root password on a new Linux instance using a customisation script during instance creation. This lets you log in through the mCloud Console when you don't have SSH key access to the instance.

Prerequisites

  • Access to the mCloud portal with permission to launch instances in the project.

  • A Linux image provided by Micron21. Micron21 images include cloud-init, which is required for the customisation script to run.

  • If you are using your own custom image, you will need to confirm it supports cloud-init or an equivalent, and adjust the script as required. Micron21 cannot provide support for custom images.

  • This process applies to new instances only. The customisation script runs on first boot and cannot be applied to an instance that has already been launched.

Steps

  1. In mCloud, go to Compute > Instances and click Launch a new instance.

  2. Configure your instance requirements as normal. Do not launch the instance yet.

  3. On the Configuration tab, add the script for your distribution from the Distribution-Specific Scripts section below.

    1. Replace SET-PASSWORD-HERE with a temporary password. Avoid using single quotes (') in the password, as this will break the script.

  4. Click Launch Instance.

  5. Once the instance finishes building, open the instance console and log in as root using the temporary password.

  6. 6. Change the root password immediately by running:

    1. passwd

      Enter and confirm a new password when prompted. This ensures the password in the customisation script can no longer be used.

Distribution-Specific Scripts

Use the script that matches the image you are deploying. Replace SET-PASSWORD-HERE with your temporary password.

Ubuntu, Debian, Rocky Linux, AlmaLinux, CentOS, RHEL, Fedora, openSUSE, Arch Linux

#!/bin/sh
echo 'root:SET-PASSWORD-HERE' | /usr/sbin/chpasswd

Alpine Linux

#!/bin/sh
echo 'root:SET-PASSWORD-HERE' | /usr/sbin/chpasswd

Alpine images may use tiny-cloud rather than cloud-init. Confirm the image supports user data scripts before relying on this method.

NixOS

#!/bin/sh
echo 'root:SET-PASSWORD-HERE' | /run/current-system/sw/bin/chpasswd

Other distributions

If your distribution is not listed above, confirm the location of chpasswd for that distribution and update the path in the script accordingly. The location can be found by running which chpasswd on an existing system running the same distribution, or by checking the distribution’s documentation.

#!/bin/sh
echo 'root:SET-PASSWORD-HERE' | /path/to/chpasswd


Helpful Unhelpful