All Products
Search
Document Center

:CreateKeyPair

更新时间:Dec 06, 2023

Creates an SSH key pair. The system stores the public key and returns the unencrypted private key. The private key is encoded with PEM in the PKCS#8 format. You must store the private key on your own and ensure its confidentiality.

Usage notes

In addition to calling CreateKeyPair, you can create a key pair by using a third-party key pair generation tool and call the ImportKeyPair operation to upload the key pair to an Alibaba Cloud region.

You can create up to 500 key pairs in each region. For more information, see the "Limits" section in Use Cloud Assistant to run commands in containers.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter

Type

Required

Example

Description

Action String Yes CreateKeyPair

The operation that you want to perform. Set the value to CreateKeyPair.

RegionId String Yes cn-hangzhou

The ID of the region in which to create the key pair. You can call the DescribeRegions operation to query the most recent region list.

KeyPairName String Yes testKeyPairName

The name of the key pair. The name must be 2 to 128 characters in length. The name must start with a letter and cannot start with http:// or https://. The name can contain letters, digits, colons (:), underscores (_), and hyphens (-).

ResourceGroupId String No rg-bp67acfmxazb4p****

The ID of the resource group to which to add the key pair.

Tag.N.Key String No TestKey

The key of tag N to add to the key pair. Valid values of N: 1 to 20. The tag key cannot be an empty string. The tag key can be up to 128 characters in length and cannot contain http:// or https://. The tag key cannot start with acs: or aliyun.

Tag.N.Value String No TestValue

The value of tag N to add to the key pair. Valid values of N: 1 to 20. The tag value can be an empty string. The tag value can be up to 128 characters in length and cannot contain http:// or https://. The tag value cannot start with acs:.

Response parameters

Parameter

Type

Example

Description

PrivateKeyBody String MIIEpAIBAAKCAQEAtReyMzLIcBH78EV2zj****

The private key of the key pair. The private key is encoded with PEM in the PKCS#8 format.

KeyPairName String testKeyPairName

The name of the key pair.

KeyPairId String ssh-bp67acfmxazb4p****

The ID of the SSH key pair.

RequestId String 473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E

The ID of the request.

KeyPairFingerPrint String 89:f0:ba:62:ac:b8:aa:e1:61:5e:fd:81:69:86:6d:6b:f0:c0:5a:**

The fingerprint of the key pair. The message-digest algorithm 5 (MD5) is used based on the public key fingerprint format defined in RFC 4716. For more information, see RFC 4716.

Examples

Sample requests

https://ecs.aliyuncs.com/?Action=CreateKeyPair
&RegionId=cn-hangzhou
&KeyPairName=testKeyPairName
&<Common request parameters>

Sample success responses

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

<CreateKeyPairResponse>
    <RequestId>473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E</RequestId>
    <KeyPairName>testKeyPairName</KeyPairName>
    <KeyPairId>ssh-bp67acfmxazb4p****</KeyPairId>
    <KeyPairFingerPrint>89:f0:ba:62:ac:b8:aa:e1:61:5e:fd:81:69:86:6d:6b:f0:c0:5a:**</KeyPairFingerPrint>
    <PrivateKeyBody>MIIEpAIBAAKCAQEAtReyMzLIcBH78EV2zj****</PrivateKeyBody>
</CreateKeyPairResponse>

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

{
  "RequestId" : "473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E",
  "KeyPairName" : "testKeyPairName",
  "KeyPairId" : "ssh-bp67acfmxazb4p****",
  "KeyPairFingerPrint" : "89:f0:ba:62:ac:b8:aa:e1:61:5e:fd:81:69:86:6d:6b:f0:c0:5a:**",
  "PrivateKeyBody" : "MIIEpAIBAAKCAQEAtReyMzLIcBH78EV2zj****"
}

Error codes

HTTP status code

Error code

Error message

Description

400 InvalidKeyPairName.Malformed Specified Key Pair name is not valid. The specified key pair name is invalid.
400 KeyPair.AlreadyExist The key pair already exist. A key pair with the same name already exists. Key pair names must be unique.
400 Duplicate.TagKey The Tag.N.Key contain duplicate key. The tag key already exists. Tag keys must be unique.
400 InvalidTagKey.Malformed The specified Tag.n.Key is not valid. Invalid Tag.N.Key value.
400 InvalidTagValue.Malformed The specified Tag.n.Value is not valid. Invalid Tag.N.Value value.
403 QuotaExceed.KeyPair The key pair quota exceeds. The maximum number of key pairs is reached.
403 QuotaExceed.Tags %s The maximum number of tags is exceeded. %s is a variable. An error message is dynamically returned based on call conditions.
404 InvalidResourceGroup.NotFound The ResourceGroup provided does not exist in our records. The resource group is not found.

For a list of error codes, see Service error codes.