SSH Key Management
After you inject an SSH key into a VM instance, you can SSH to the VM instance without entering a password.
Steps
- Install cloud-init.Currently, you can inject an SSH key into a VM instance by using cloud-init. Before you can inject an SSH key, install cloud-init on the VM image first.
- Install cloud-init. Recommended versions: 0.7.9, 17.1, 19.4, and later.
- After you install cloud-init, the SSH password authentication is
disabled by default. To enable the SSH password authentication, set
the
ssh_pwauth
option under /etc/cloud/cloud.cfg to 1.
- Generate an SSH key.
- The SSH key is generated by running the ssh-keygen command and is stored in /root/.ssh/id_rsa.pub by default.
- Paste the file content into the SSH Key input box.
- Inject the SSH key into the VM instance.You can inject the SSH key into the VM instance by the following two methods:
- Method 1: When you create a VM instance, inject an SSH key.
- Method 2: For existing VM instances, inject an SSH key by performing the Set SSH KEY action.
After you inject the SSH key, you can check the basic information about the SSH key on the details page of the VM instance. The basic information includes the corresponding username and host information.

- If you inject an SSH key when you create a VM instance, the SSH key takes effect upon the first VM starts.
- If you inject an SSH key into an existing VM instance for the first time, reboot the VM instance to take effect.
- If you inject an SSH key into a VM instance that already has an SSH key,
clean up the previous configurations by running the
rm -rf /var/lib/cloud/instances
command, inject the new SSH key, and reboot the VM instance to take effect. - If you need to delete an SSH key, only the SSH key information recorded in the system is deleted. The SSH key information injected into the VM configurations is not deleted. To delete the SSH key information completely, manually clean up the VM configuration file /root/.ssh/authorized_keys.