All Products
Search
Document Center

Elastic Compute Service:CreateKeyPair

Last Updated:Jul 09, 2024

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 properly store the private key and ensure its confidentiality.

Operation description

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

Up to 500 key pairs can be created in each region. For more information, see the "SSH key pair limits" section in Limits .

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer.

Authorization information

There is currently no authorization information disclosed in the API.

Request parameters

ParameterTypeRequiredDescriptionExample
RegionIdstringYes

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.

cn-hangzhou
KeyPairNamestringYes

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 (-).

testKeyPairName
ResourceGroupIdstringNo

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

rg-bp67acfmxazb4p****
Tagarray<object>No

The tags of the key pair.

objectNo
KeystringNo

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.

TestKey
ValuestringNo

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

TestValue

Response parameters

ParameterTypeDescriptionExample
object
PrivateKeyBodystring

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

MIIEpAIBAAKCAQEAtReyMzLIcBH78EV2zj****
KeyPairNamestring

The name of the key pair.

testKeyPairName
KeyPairIdstring

The ID of the key pair.

ssh-bp67acfmxazb4p****
RequestIdstring

The request ID.

473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E
KeyPairFingerPrintstring

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.

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

Examples

Sample success responses

JSONformat

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

Error codes

HTTP status codeError codeError messageDescription
400InvalidKeyPairName.MalformedSpecified Key Pair name is not valid.-
400KeyPair.AlreadyExistThe key pair already exist.A key pair with the same name already exists. Key pair names must be unique.
400Duplicate.TagKeyThe Tag.N.Key contain duplicate key.The specified tag key already exists. Tag keys must be unique.
400InvalidTagKey.MalformedThe specified Tag.n.Key is not valid.The specified Tag.N.Key parameter is invalid.
400InvalidTagValue.MalformedThe specified Tag.n.Value is not valid.The specified tag value is invalid.
403QuotaExceed.KeyPairThe key pair quota exceeds.The maximum number of key pairs has been reached.
403QuotaExceed.Tags%sThe number of specified tags exceeds the upper limit. %s is a variable. An error message is dynamically returned based on call conditions.
404InvalidRegionId.NotFoundThe RegionId provided does not exist in our records.The RegionId provided does not exist
404InvalidResourceGroup.NotFoundThe ResourceGroup provided does not exist in our records.The specified resource group does not exist.

For a list of error codes, visit the Service error codes.

Change history

Change timeSummary of changesOperation
No change history