Updated on 2024-08-06 GMT+08:00

Creating and Importing an SSH Key Pair (V2)

Function

This API is used to create an SSH key pair or import a public key to HUAWEI CLOUD to generate a key pair.

After an SSH key pair is created, you need to download the private key to a local directory. Then, you can use this private key to log in to an ECS. For ECS security purposes, the private key can be downloaded only once. Keep it secure.

URI

  • URI format

    POST /v2/{project_id}/os-keypairs

  • Parameter description
    Table 1 Parameter description

    Parameter

    Mandatory

    Type

    Description

    project_id

    Yes

    String

    Project ID

Requests

When creating an SSH key pair, you only need to set the name. When importing an SSH key pair, you must set the public_key parameter.

Table 2 Request parameters

Parameter

Mandatory

Type

Description

keypair

Yes

Object

Information about the created or imported SSH key pair. For details, see Table 3.

Table 3 keypair field description

Parameter

Mandatory

Type

Description

public_key

No

String

Character string of a public key to be imported

type

No

String

Type of a key pair. The value is ssh or x509.

name

Yes

String

Name of an SSH key pair.

A new key pair cannot use the same name as an existing one.

The value contains a maximum of 64 characters, including only letters, digits, underscores(_), and hyphens (-).

user_id

No

String

ID of the user to whom an SSH key pair belongs

Responses

Table 4 Response parameters

Parameter

Mandatory

Type

Description

keypair

Yes

Object

SSH key pair information. For details, see Table 5.

Table 5 keypair field description

Parameter

Mandatory

Type

Description

fingerprint

Yes

String

Fingerprint information about an SSH key pair

name

Yes

String

Name of an SSH key pair

public_key

Yes

String

Public key information about an SSH key pair

private_key

No

String

Private key information about an SSH key pair.

  • The information about the private key is contained in the response for creating an SSH key pair.
  • The information about the private key is not contained in the response for importing an SSH key pair.

user_id

Yes

String

ID of the user to whom an SSH key pair belongs

Examples

  • Creating an SSH key pair
    • Request example for creating an SSH key pair
      {     "keypair": {             
                "type": "ssh",           
                "name": "demo"              
             }
      }
    • Response example for creating an SSH key pair
      {
          "keypair": {
              "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCyNtFZM04PFxERvZU5OBKTKr3mtRZABe5/+zX81lTgDFCBfq6OXia47M4qXOa3ciBEKKZF+fMfs8U2UNB9aK1R/uORsoEFtxSgZ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y//BavPSgq4v\nWuFHgx1sPQK49KcSLZfF6UxkPw0KHBc5R9RkfYBAIdGNwENF2xyoYLLdnUtF4hRq\n1q2DC3oklBZibH2tc6+hQ2aCWSeMvQbIvxTYV70EFzwR5f4O5LIskCm/AoGBAMyn\nA7DOQdvcf4aexSYL4kGp70ERMOCtwr/d+O5RswARoyAQOxp4a7/TyFuGjnlT//bR\nEYacXV1AieIdeJF3PgeUIR1QnUlNYD9Rufs14fs+5idQ7Evn1gvXv0HpBYTY7wNu\nWTrWbsznY0fNIrGT4bQR6QpdvIuR5TBJf6HIAKyDAoGAFhKf3D2HbfraXkqC6V3A\nNAN9Uy7bxwxOXZPha7Ky4QrspRGt4MNNk0q6X7ps3A0mJDi3jPSKoga2+3qJx37j\nbtM4Xe97qb0IUWDkThUZ5fvtbBuSRAVEFlAIXeKrSwAZz+PRtY0ZGFhFrZXQzZAo\n4058eXmjN05qYFpnKIEjEQ8CgYEAwELzW6oaAzR+dfk428p0UB4W0HkXAy0a9efS\nUgpc8Oag6qF09SRGjdunshySQvegU78MCPtjVxUntE7dk0OD+di213SBn3jawAHG\niHORjtkDndIPfCwcUdnpK0GAVtL6kK2dlIIZa9TB15WnT07Pzry4w21WkYSJ3Thf\neJyNzYMCgYA8OvpKMdaEXFeNZWHDE1Q2VmpxvP/D6u6s4SBuyy8eac1qqku/s7zc\nsuFd/o9wbBgzsf4eN8tNJ4bxrArRXvf9WyH7xd4PE3DvVJnz5S+8Nqj2Z0KCAqPD\nibDbFxBYHcMIdwC2JBGQZIXpkST2jG9wZho5KghX4yiHSOPr2V25/g==\n-----END RSA PRIVATE KEY-----\n",
              "user_id": "6fc0d2cbbfab40b199874b97097e913d",
              "name": "demo",
              "fingerprint": "b4:9a:c3:12:c4:90:bf:8e:7a:e2:70:10:c3:00:55:3f"
         }
      }
  • Importing an SSH key pair
    • Request example for importing an SSH key pair
      {
          "keypair": {
              "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCyNtFZM04PFxERvZU5OBKTKr3mtRZABe5/+zX81lTgDFCBfq6OXia47M4qXOa3ciBEKKZF+fMfs8U2UNB9aK1R/uORsoEFtxSgZnWG6p4Ct1vnrqwDD934VaDFPEn+h3JeAfvTB+Ag1YQ9zh9uYyE9Z3qZcC9+Ui93BDGdBtQeav4odxdwXcr2mT2jJV0nsocV0O4UcKM8BaIm8eqbcroZEkyxqT3mUoSbmGx1hrngjBsP1ufgwJ6D85LFGQC1SjIOLvsR9i6v41BaLF8/kygvKOh2HlNVSMx38g52sTqoQ/xb3f8vR1VDXliAuD0frrG2Fy5wK4rOAnjuX9nh0bC9 Generated-by-Nova\n",
              "type": "ssh",
              "name": "demo1",
              "user_id": "fake"
          }
      }
    • Response example for importing an SSH key pair
      {
          "keypair": {
              "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCyNtFZM04PFxERvZU5OBKTKr3mtRZABe5/+zX81lTgDFCBfq6OXia47M4qXOa3ciBEKKZF+fMfs8U2UNB9aK1R/uORsoEFtxSgZnWG6p4Ct1vnrqwDD934VaDFPEn+h3JeAfvTB+Ag1YQ9zh9uYyE9Z3qZcC9+Ui93BDGdBtQeav4odxdwXcr2mT2jJV0nsocV0O4UcKM8BaIm8eqbcroZEkyxqT3mUoSbmGx1hrngjBsP1ufgwJ6D85LFGQC1SjIOLvsR9i6v41BaLF8/kygvKOh2HlNVSMx38g52sTqoQ/xb3f8vR1VDXliAuD0frrG2Fy5wK4rOAnjuX9nh0bC9 Generated-by-Nova\n",
              "user_id": "6fc0d2cbbfab40b199874b97097e913d",
              "name": "demo1",
              "fingerprint": "b4:9a:c3:12:c4:90:bf:8e:7a:e2:70:10:c3:00:55:3f"
          }
      }

Status Codes

For details, see Status Codes.