• Bare Metal Server

bms
  1. Help Center
  2. Bare Metal Server
  3. User Guide
  4. Instance
  5. (Optional) Injecting User Data into BMSs

(Optional) Injecting User Data into BMSs

Application Scenarios

Use the user data injection function to inject user data into BMSs to:

  • Use scripts to simplify BMS configuration.
  • Use scripts to initialize the BMS OS configuration.
  • Upload your scripts to BMSs during BMS creation.
  • Use scripts to perform other operations.

Restrictions

  • For Linux:
    • The image that is used to create BMSs must have Cloud-Init installed.
    • The user data to be injected must be less than or equal to 32 KB.
    • User data uploaded as text can contain only ASCII characters. User data uploaded as a file can contain any characters.
  • For Windows:
    • The image that is used to create BMSs must have Cloudbase-Init installed.
    • The user data to be injected must be less than or equal to 32 KB.
    • User data uploaded as text can contain only ASCII characters. User data uploaded as a file can contain any characters.

Use Methods

  1. Create a Cloud-Config script, the format of which complies with Cloud-Config script specifications. For details, see section Related Links.
  2. During BMS creation, copy the Cloud-Config script content to the user data injection text box, or select the Cloud-Config file and upload it.
  3. The created BMS automatically runs Cloud-Init/Cloudbase-Init and the Cloud-Config script upon startup.

Example 1

This use case illustrates how to use the user data injection function to simplify BMS configuration.

In this example, vim is configured to enable syntax highlighting, display line numbers, and set the tab stop to 4. Configuration file .vimrc is created and injected into the /root/.vimrc directory during BMS creation. After the BMS is created, vim is automatically configured based on your requirements. This helps to improve BMS configuration efficiency, especially in batch ECS creation scenarios.

The content of the script file to be injected is as follows:

#cloud-config
write_files:
  - path: /root/.vimrc
    content: |
      syntax on
      set tabstop=4
      set number      

Example 2

This use case illustrates how to use the user data injection function to reset the password for logging in to a Linux BMS.

In this example, the password of user root is reset to "******".

NOTE:

The new password must meet the password complexity requirements listed in Table 1.

Table 1 Password requirements

Parameter

Requirements

Example Value

Password

  • Consists of 8 characters to 26 characters.
  • Must contain at least three of the following character types:
    • Uppercase letters
    • Lowercase letters
    • Digits
    • Special characters !@$%^-_=+[]{}:,./?
  • Cannot contain the username or the username in reverse.
  • Cannot contain more than two characters in the same sequence as they appear in the username. (This requirement applies only to Windows BMSs.)

Test12$@

The content of the script file to be injected is as follows. (Retain the indentation in the following script.)

#cloud-config
chpasswd:
  list: |
    root:******
  expire: False

After the BMS is created, you can use the reset password to log in to it. To ensure system security, change the password of user root after logging in to the BMS for the first time.

Example 3

This use case illustrates how to use the user data injection function to create a user on a Windows BMS and configure the password for the user.

In this example, the user's username is abc, its password is ******, and the user is added to the administrators user group.

NOTE:

The new password must meet the password complexity requirements listed in Table 2.

Table 2 Password requirements

Parameter

Requirements

Example Value

Password

  • Consists of 8 characters to 26 characters.
  • Must contain at least three of the following character types:
    • Uppercase letters
    • Lowercase letters
    • Digits
    • Special characters !@$%^-_=+[]{}:,./?
  • Cannot contain the username or the username in reverse.
  • Cannot contain more than two characters in the same sequence as they appear in the username. (This requirement applies only to Windows BMSs.)

Test12$@

The content of the script file to be injected is as follows:

rem cmd
net user abc ****** /add
net localgroup administrators abc /add

After the BMS is created, you can use the created username and password to log in to it.

Related Links

For more descriptions, visit either of the following web pages: