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

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


Can't find what you're looking for?

Create or manage support tickets directly with Micron21

You will need to register a new account if this is the first time lodging a ticket.

If you have previous lodged a ticket either online, email or over the phone you will already have an account. Please reset your password, if you have not logged into the support portal before.

Lodge a ticket Manage existing tickets

Need to send us information securely? Use our Escrow service here

Need more advanced support?

Micron21 provides a comprehensive approach to customer care that starts with a base 24/7 support that is included free with every service we offer - there are no charges to enjoy a basic level of support with Micron21 and you are not restricted in how you contact us to receive assistance any time of day or night.

For those who require more advanced support though, our Customer Care plans and Ad-Hoc support are designed to completely remove the complexity of IT management - from taking full responsibility for your entire infrastructure or tailoring a custom approach, we have the capability and know-how.

 

If you've organised remote assistance from Micron21, click here to connect

w

Sign up for the Micron21 Newsletter