You need to configure Cloud-Init after it is installed.
The following operations are required:
For details, see Configure Cloud-Init.
For details, see Check the Cloud-Init Configuration.
Run the following command to open the sshd_config file using the vi editor:
vi /etc/ssh/sshd_config
For SUSE and openSUSE, change the values of the following parameters in the sshd_config file to no:
vi /etc/cloud/cloud.cfg
This step is only for Cloud-Init 18.3 or later.

For Ubuntu and Debian, set the value of manage_etc_hosts in the /etc/cloud/cloud.cfg file to localhost. Otherwise, switching to user root from a user other than root may time out.
Take Ubuntu as an example.
cat /etc/cloud/set_linux_random_password.sh
#!/bin/bash password=$(cat /dev/urandom | tr -dc 'A-Za-z0-9!@#$%&+=' | head -c 9) echo "linux:$password" | chpasswd sed -i -e '/^Login/d' /etc/issue sed -i -e '/^Initial/d' /etc/issue sed -i -c -e '/^$/d' /etc/issue echo -e "\nInitial login with linux:$password\n" >> /etc/issue
You can run the chmod +x /etc/cloud/set_linux_random_password.sh command to add execute permissions of set_linux_random_password.sh.
echo -e '\e[1;31m#################################\\e[0m' > /etc/motd
echo -e '\e[1;31m# Important !!! #\e[0m' >> /etc/motd
echo -e '\e[1;31m# Please change password for user linux after first login. #\e[0m' >> /etc/motd
echo -e '\e[1;31m#################################\e[0m' >> /etc/motd
echo -e '' >> /etc/motd
Ensure that the configuration file format (such as alignment and spaces) is consistent with the provided example.
system_info:
# This will affect which distro class gets used
distro: rhel
# Default user name + that default users groups (if added/used)
default_user:
name: linux //Username for login
lock_passwd: False //Login using a password is enabled. Note that some OSs use value 0 to enable the password login.
gecos: Cloud User
groups: users //Optional. Add users to other groups that have been configured in /etc/group.
passwd: $6$I63DBVKK$Zh4lchiJR7NuZvtJHsYBQJIg5RoQCRLS1X2Hsgj2s5JwXI7KUO1we8WYcwbzeaS2VNpRmNo28vmxxCyU6LwoD0
sudo: ["ALL=(ALL) NOPASSWD:ALL"] // Assign the root rights to the user.
shell: /bin/bash //Execute shell in bash mode.
# Other config here will be given to the distro class and/or path classes
paths:
cloud_dir: /var/lib/cloud/
templates_dir: /etc/cloud/templates/
ssh_svcname: sshd
bootcmd:
- [cloud-init-per, instance, password, bash,
/etc/cloud/set_linux_random_password.sh]
The value of passwd is encrypted using SHA512 (which is used as an example). For more details, see https://cloudinit.readthedocs.io/en/latest/topics/examples.html.
For details about how to encrypt a password and generate ciphertext, see the following (encrypting password cloud.1234 is used as an example):
[root@** ~]# python -c "import crypt, getpass, pwd; print crypt.mksalt()"
$6$I63DBVKK
[root@** ~]# python -c "import crypt, getpass, pwd; print crypt.crypt('cloud.1234', '\$6\$I63DBVKK')"
$6$I63DBVKK$Zh4lchiJR7NuZvtJHsYBQJIg5RoQCRLS1X2Hsgj2s5JwXI7KUO1we8WYcwbzeaS2VNpRmNo28vmxxCyU6LwoD0
datasource_list: [ OpenStack ]
datasource:
OpenStack:
metadata_urls: ['http://169.254.169.254']
max_wait: 120
timeout: 5
If the Cloud-Init version is 0.7.9 or later, add the following content to /etc/cloud/cloud.cfg:
network: config: disabled
The added content must be in the YAML format.

Move ssh from the bottom to the top to speed up the SSH login.

vi /usr/lib/python2.7/site-packages/cloudinit/sources/__init__.py
Press i to enter editing mode. Search for toks. The following information is displayed:
if toks:
toks = str(toks).split('.')
else:
toks = ["ip-%s" % lhost.replace(".", "-")]
else:
toks = lhost.split(".novalocal")
if len(toks) > 1:
hostname = toks[0]
#domain = '.'.join(toks[1:])
else:
hostname = toks[0]
if fqdn and domain != defdomain:
return "%s.%s" % (hostname, domain)
else:
return hostname
After the modification is complete, press Esc to exit the editing mode and enter :wq! to save the configuration and exit.

cd /usr/lib/python2.7/site-packages/cloudinit/sources/
rm -rf __init__.pyc
rm -rf __init__.pyo
rm -rf /var/log/cloud-init*
vim /etc/cloud/cloud.cfg.d/05_logging.cfg

Run the following command to check whether Cloud-Init has been properly configured:
cloud-init init --local
(Optional) Run the following command to set the password validity period to the maximum:
chage -M 99999 $user_name
user_name is a system user, such as user root.
You are advised to set the password validity period to 99999.