All Products
Search
Document Center

ENS:AttachKeyPair

Last Updated:Mar 25, 2026

Attaches an SSH key pair to up to 30 instances in a single call.

Operation description

You can only attach a key pair to stopped instances.

  • Specify up to 30 instances per call.

  • Specify either KeyPairName or KeyPairId.

  • We recommend using KeyPairId, as KeyPairName will be deprecated.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

No authorization for this operation. If you encounter issues with this operation, contact technical support.

Request parameters

Parameter

Type

Required

Description

Example

KeyPairName

string

No

The key pair name.

test-kp

InstanceIds

array

Yes

A list of instance IDs.

["i-50f8q9mbfjzlkuk9znjglnne3"]

string

No

The instance ID.

i-xxx

KeyPairId

string

No

The unique ID of the key pair.

ssh-xxx

Response elements

Element

Type

Description

Example

object

The response object.

RequestId

string

The request ID.

xx-xx-xx-xx

KeyPairName

string

The key pair name.

ssh-xxx

FailCount

integer

The number of instances where the attachment failed.

1

TotalCount

integer

The total number of instances in the request.

3

Results

array<object>

The attachment results for each instance.

object

Code

integer

The status code for the operation. A value of 200 indicates success.

200

InstanceId

string

The instance ID.

i-xxx

Message

string

The response message. If the Code is 200, this message is successful.

successful

Success

boolean

Indicates if the operation succeeded for the instance.

true

KeyPairId

string

The key pair ID.

ssh-xxx

Examples

Success response

JSON format

{
  "RequestId": "xx-xx-xx-xx",
  "KeyPairName": "ssh-xxx",
  "FailCount": 1,
  "TotalCount": 3,
  "Results": [
    {
      "Code": 200,
      "InstanceId": "i-xxx",
      "Message": "successful",
      "Success": true
    }
  ],
  "KeyPairId": "ssh-xxx"
}

Error codes

HTTP status code

Error code

Error message

Description

400 NoPermission Permission denied.
400 InvalidParameter.%s The specified field %s invalid. Please check it again.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.