You can call this operation to import the public key of an RSA-encrypted key pair that you created using a third-party tool. After the key pair is imported, the public key is stored on Alibaba Cloud. You must store the private key on your own and ensure its confidentiality.

Description

When you call this operation, note that:

  • A maximum of 500 key pairs can be created in each region.
  • You must use one of the following methods to encrypt your key pair:
    • RSA
    • DSA
    • SSH-RSA
    • SSH-DSS
    • ECDSA
    • ssh-rsa-cert-v00@openssh.com
    • ssh-dss-cert-v00@openssh.com
    • ssh-rsa-cert-v01@openssh.com
    • ssh-dss-cert-v01@openssh.com
    • ecdsa-sha2-nistp256-cert-v01@openssh.com
    • ecdsa-sha2-nistp384-cert-v01@openssh.com
    • ecdsa-sha2-nistp521-cert-v01@openssh.com

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 ImportKeyPair

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

KeyPairName String Yes FinanceJoshuaV24

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

PublicKeyBody String Yes xxxxxxxxxxxxxx

The public key of the key pair.

RegionId String Yes cn-hangzhou

The ID of the region. You can call the DescribeRegions operation to query the most recent region list.

Tag.N.Key String No TestKey

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

Tag.N.Value String No TestValue

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

ResourceGroupId String No rg-bp67acfmxazb4ph***

The ID of the enterprise resource group to which the SSH key pair belongs.

Response parameters

Parameter Type Example Description
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.

KeyPairName String FinanceJoshauV24

The name of the key pair.

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

The ID of the request.

Examples

Sample requests

https://ecs.aliyuncs.com/?Action=ImportKeyPair
&RegionId=cn-qingdao
&PublicKeyBody=xxxxxxxxxxxxxx
&KeyPairName=test
&<Common request parameters>

Sample success responses

XML format

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

JSON format

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

Error codes

HTTP status code Error code Error message Description
400 InvalidKeyPairName.Malformed Specified Key Pair name is not valid. The error message returned because the KeyPairName parameter is invalid.
403 QuotaExceed.KeyPair The key pair quota exceeds. The error message returned because the maximum number of key pairs has been reached.
400 InvalidPublicKeyBody.Malformed The PublicKeyBody format is not supported. The error message returned because the public key format is not supported.
400 MissingParameter The input parameter "PublicKeyBody" that is mandatory for processing this request is not supplied. The error message returned because the required PublicKeyBody parameter is not specified.
400 KeyPair.AlreadyExist The key pair already exist. The error message returned because a key pair with the same name already exists. Duplicate key pairs cannot be added.
500 InternalError The request processing has failed due to some unknown error. The error message returned because an internal error has occurred. Try again later. If the problem persists, submit a ticket.
404 InvalidResourceGroup.NotFound The ResourceGroup provided does not exist in our records. The error message returned because the specified resource group does not exist.

For a list of error codes, visit the API Error Center.