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

  1. 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.
    1. Install cloud-init. Recommended versions: 0.7.9, 17.1, 19.4, and later.
    2. 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.
  2. Generate an SSH key.
    1. The SSH key is generated by running the ssh-keygen command and is stored in /root/.ssh/id_rsa.pub by default.
    2. Paste the file content into the SSH Key input box.
  3. 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.

Note:
  • 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.

Image Downloads

You can download the corresponding images for test use from the CentOS and Ubuntu official websites. The download links are as follows:
  • CentOS 7: Click here.
  • Ubuntu 14.04: Click here.