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

Creating and Importing an SSH Key Pair (V2.1)

Function

This API is used to create and import an SSH key pair, and allows you to manage the private key in the cloud.

URI

  • URI format

    POST /v2.1/{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

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

key_protection

No

Object

Management and protection of the private key of an SSH key pair. For details, see Table 4.

Table 4 key_protection field description

Parameter

Mandatory

Type

Description

private_key

No

String

Character string of a private key to be imported

encryption

Yes

Object

Method to encrypt and store private keys. For details, see Table 5.

Table 5 encryption field description

Parameter

Mandatory

Type

Description

type

Yes

String

Value options: kms or default

  • default refers to the default encryption method. It is applicable to sites where the KMS service is unavailable.
  • kms indicates that the KMS service is leveraged for the encryption.

If the KMS service is unavailable, set this parameter to default.

kms_key_name

No

String

Name of a KMS key.

If type is set to kms, enter the name of the key obtained from KMS.

Responses

Table 6 Response parameters

Parameter

Mandatory

Type

Description

keypair

Yes

Object

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

Table 7 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

Yes

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

User to whom an SSH key pair belongs

Examples

  • Creating an SSH key pair
    • Request example for creating an SSH key pair
      {
          "keypair": {
              "name": "demo1"
          }
      }
    • Response example for creating an SSH key pair
      {
          "keypair": {
              "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCXKzohKbFOqubYNunFNsrEYlk9NEIJIFvbmTe/LTeMzFIPKM53Zu2sYr/uuNcziPkWpFchXdkD+O/Bf2ZzKaR1DYPMWss9TkaqU4RQ7CIBW7ChJF1Qzc1JPRBmKe6e8qs1QBBoS1QvXgSjbuf2Fb1yncSbphmQV8+5KA8xkxz4XdM1/gSAZZ14rJrMjgp7jCdgxWiHNcDuKxaPt+0eO8rEG/gxR7J0b9Uk53ao/xjLoKXYdLLiYUaha0fHdW3t6Lw1NdzUMmKnlLqN9O37Tbg7vM0nN4UJt0XXvM45KfnJiMx0HUKXdWkUj9cE8VBDPw/gBbQzSpJHgQFG7mNDZubN Generated-by-Nova\n",
              "private_key": "-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEAlys6ISmxTqrm2DbpxTbKxGJZPTRCCSBb25k3vy03jMxSDyjO\nd2btrGK/7rjXM4j5FqRXIV3ZA/jvwX9mcymkdQ2DzFrLPU5GqlOEUOwiAVuwoSRd\nUM3NST0QZinunvKrNUAQaEtUL14Eo27n9hW9cp3Em6YZkFfPuSgPMZMc+F3TNf4E\ngGWdeKyazI4Ke4wnYMVohzXA7isWj7ftHjvKxBv4MUeydG/VJOd2qP8Yy6Cl2HSy\n4mFGoWtHx3Vt7ei8NTXc1DJip5S6jfTt+024O7zNJzeFCbdF17zOOSn5yYjMdB1C\nl3VpFI/XBPFQQz8P4AW0M0qSR4EBRu5jQ2bmzQIDAQABAoIBAFwm1s3Gi7bICec+\nOm2lhCAJUBs2UxcbKcQJd+lL2DQ1jcR9/LbfAP34SMZu2Ykp86Zw0kid3CBGzWko\nj7yeYwmUDocxxfl+USedt+hYujYXvenNsDEE9CK0Xd3ZrAQrLGFOx3G8kfo6FxvG\nDRN/lzhaorK7o5PRY+icWf6/joZ8Q96scHmm0ob5rtBkUYcek+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"e4f380899b1248918f3d37098dc63746",
              "name": "demo123",
              "fingerprint": "49:ef:73:2b:9b:7f:2e:0c:58:d3:e3:42:8e:28:04:3b"
          }
      }
      or
      {
          "error_code": "KPS.XXXX",
          "error_msg": "XXXX"
      }
  • Creating an SSH key pair and managing the private key in the cloud
    • Request example for creating an SSH key pair and managing the private key in the cloud
      {
          "keypair": {
              "name": "demo2",
              "key_protection": {
                  "encryption": {
                      "type": "kms",
                      "kms_key_name": "demo"
                  }
              }
          }
      }
    • Response example for creating an SSH key pair and managing the private key in the cloud
      {
          "keypair": {
              "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCXKzohKbFOqubYNunFNsrEYlk9NEIJIFvbmTe/LTeMzFIPKM53Zu2sYr/uuNcziPkWpFchXdkD+O/Bf2ZzKaR1DYPMWss9TkaqU4RQ7CIBW7ChJF1Qzc1JPRBmKe6e8qs1QBBoS1QvXgSjbuf2Fb1yncSbphmQV8+5KA8xkxz4XdM1/gSAZZ14rJrMjgp7jCdgxWiHNcDuKxaPt+0eO8rEG/gxR7J0b9Uk53ao/xjLoKXYdLLiYUaha0fHdW3t6Lw1NdzUMmKnlLqN9O37Tbg7vM0nN4UJt0XXvM45KfnJiMx0HUKXdWkUj9cE8VBDPw/gBbQzSpJHgQFG7mNDZubN Generated-by-Nova\n",
              "private_key": "-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEAlys6ISmxTqrm2DbpxTbKxGJZPTRCCSBb25k3vy03jMxSDyjO\nd2btrGK/7rjXM4j5FqRXIV3ZA/jvwX9mcymkdQ2DzFrLPU5GqlOEUOwiAVuwoSRd\nUM3NST0QZinunvKrNUAQaEtUL14Eo27n9hW9cp3Em6YZkFfPuSgPMZMc+F3TNf4E\ngGWdeKyazI4Ke4wnYMVohzXA7isWj7ftHjvKxBv4MUeydG/VJOd2qP8Yy6Cl2HSy\n4mFGoWtHx3Vt7ei8NTXc1DJip5S6jfTt+024O7zNJzeFCbdF17zOOSn5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tZFkmPrt5KaeE5BXGq0vzP8wpJC5+cln+RX13BYzLJzL\nLr3COQKBgDJjY0qop3aSG+1tSkMJtOFdb2+qXiqaE+Wxv03SOkPx8LBz+taNz+DE\nR7THDNXSrS85WVc3ozE8hULBX12iIWpr5kb5lRaw3ZgX6wBnSSpdQu49v3nFoGJk\nUWY95pQ/BWQaX0q4KxzRVxup+7gwT5sKFXU+ktFtsGMYoDoSzbZS\n-----END RSA PRIVATE KEY-----\n",
              "user_id": "e4f380899b1248918f3d37098dc63746",
              "name": "demo123",
              "fingerprint": "49:ef:73:2b:9b:7f:2e:0c:58:d3:e3:42:8e:28:04:3b"
          }
      }
  • Importing the public key of the SSH key pair
    • Request example for importing the public key of an SSH key pair
      {
          "keypair": {
              "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCyNtFZM04PFxERvZU5OBKTKr3mtRZABe5/+zX81lTgDFCBfq6OXia47M4qXOa3ciBEKKZF+fMfs8U2UNB9aK1R/uORsoEFtxSgZnWG6p4Ct1vnrqwDD934VaDFPEn+h3JeAfvTB+Ag1YQ9zh9uYyE9Z3qZcC9+Ui93BDGdBtQeav4odxdwXcr2mT2jJV0nsocV0O4UcKM8BaIm8eqbcroZEkyxqT3mUoSbmGx1hrngjBsP1ufgwJ6D85LFGQC1SjIOLvsR9i6v41BaLF8/kygvKOh2HlNVSMx38g52sTqoQ/xb3f8vR1VDXliAuD0frrG2Fy5wK4rOAnjuX9nh0bC9 Generated-by-Nova\n",
              "name": "demo3"
          }
      }
    • Response example for importing the public key of an SSH key pair
      {
          "keypair": {
              "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCyNtFZM04PFxERvZU5OBKTKr3mtRZABe5/+zX81lTgDFCBfq6OXia47M4qXOa3ciBEKKZF+fMfs8U2UNB9aK1R/uORsoEFtxSgZnWG6p4Ct1vnrqwDD934VaDFPEn+h3JeAfvTB+Ag1YQ9zh9uYyE9Z3qZcC9+Ui93BDGdBtQeav4odxdwXcr2mT2jJV0nsocV0O4UcKM8BaIm8eqbcroZEkyxqT3mUoSbmGx1hrngjBsP1ufgwJ6D85LFGQC1SjIOLvsR9i6v41BaLF8/kygvKOh2HlNVSMx38g52sTqoQ/xb3f8vR1VDXliAuD0frrG2Fy5wK4rOAnjuX9nh0bC9 Generated-by-Nova\n",
              "user_id": "e4f380899b1248918f3d37098dc63746",
              "name": "demo1",
              "fingerprint": "b4:9a:c3:12:c4:90:bf:8e:7a:e2:70:10:c3:00:55:3f"
          }
      }
      or
      {
          "error_code": "KPS.XXXX",
          "error_msg": "XXXX"
      }
  • Importing the public key of the SSH key pair and managing the private key in the cloud
    • Request example for importing the public key of an SSH key pair and managing the private key in the cloud
      {
          "keypair": {
              "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDb26UrW0htRbE/Ygf8EPhzanBCc+5yEhkgmeSb2hTe48YRE5FdJKH6tueyj+vw5guoKjAITLjqZCqffGYXz/7aXpFt244b9tTzh2l43uNtEZC+XZtc6KiBgfWupFI8O2i9YjJqdadsr+4Ad4AtIBbF++qsSJN4YycPX//Gl8ja6AGPy4sdv8DZ40Gr8d+dMQ4pAsnUEtZ3jJ6NLdQU2CE1JhBdg3hbVbeh44gqQtSjhxWaSTlr+NbVxSERtXXpsQWsid6qM1RhqH2+02cqXq5oNs4JLdu56pcTgSO5azTsGYJi6j5qp5BAdjMrFtHjbaeVVWtkO1XQxfpueCJ470lx Generated-by-Nova\n",
              "name": "demo4",
              "key_protection": {
                  "private_key": "-----BEGIN RSA PRIVATE KEY-----\nMIIEpQIBAAKCAQEA29ulK1tIbUWxP2IH/BD4c2pwQnPuchIZIJnkm9oU3uPGEROR\nXSSh+rbnso/r8OYLqCowCEy46mQqn3xmF8/+2l6RbduOG/bU84dpeN7jbRGQvl2b\nXOiogYH1rqRSPDtovWIyanWnbK/uAHeALSAWxfvqrEiTeGMnD1//xpfI2ugBj8uL\nHb/A2eNBq/HfnTEOKQLJ1BLWd4yejS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scZ\ncVPlYvSU8/0CGN2IRvWMdRhgXLnGyYF4BuDd0J4hAH50u6ETiwivGfmogS6ywJAX\nqdzx2dOz+e/n7wceafkhNH2zBbmM9glNKgok7DxfbcF6is7IALoDJ4xbOHu4ZEHD\n55sbrE0CgYEAuOuiISgfbujENFFPW0nvUmNqbkAH5YW1oUIWYA+64z7wcWyvzxRS\nYml2XLWyrJy3JNzHpLoe4mCBxz+HGrftZ0/qfQ/WDZrY/Djp7/xIkPyI9EwsRTYC\nr1PtWvVws3y3hgdo6WVQMaeUqtLSiTugyuuPqidH+/QtwxObunNH6Ns=\n-----END RSA PRIVATE KEY-----\n",
                  "encryption": {
                      "type": "kms",
                      "kms_key_name": "testName"
                  }
              }
          }
      }
    • Response example for importing the public key of an SSH key pair and managing the private key in the cloud
      {
          "keypair": {
              "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCyNtFZM04PFxERvZU5OBKTKr3mtRZABe5/+zX81lTgDFCBfq6OXia47M4qXOa3ciBEKKZF+fMfs8U2UNB9aK1R/uORsoEFtxSgZnWG6p4Ct1vnrqwDD934VaDFPEn+h3JeAfvTB+Ag1YQ9zh9uYyE9Z3qZcC9+Ui93BDGdBtQeav4odxdwXcr2mT2jJV0nsocV0O4UcKM8BaIm8eqbcroZEkyxqT3mUoSbmGx1hrngjBsP1ufgwJ6D85LFGQC1SjIOLvsR9i6v41BaLF8/kygvKOh2HlNVSMx38g52sTqoQ/xb3f8vR1VDXliAuD0frrG2Fy5wK4rOAnjuX9nh0bC9 Generated-by-Nova\n",
              "user_id": "e4f380899b1248918f3d37098dc63746",
              "name": "demo1",
              "fingerprint": "b4:9a:c3:12:c4:90:bf:8e:7a:e2:70:10:c3:00:55:3f"
          }
      }
      or
      {
          "error_code": "KPS.XXXX",
          "error_msg": "XXXX"
      }

Status Codes

For details, see Status Codes.