You can call this operation to detach an SSH key pair from one or more Linux instances.

Description

When you call this operation, take note of the following items:

  • After you detach an SSH key pair, you must restart the instance (RebootInstance) for the operation to take effect.
  • By default, the username and password authentication is used after you detach an SSH key pair.

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 DetachKeyPair

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

InstanceIds String Yes ["i-xxxxxxxxx", "i-yyyyyyyyy", ... "i-zzzzzzzzz"]

The IDs of instances from which you want to detach the SSH key pair. It can be a JSON array that consists of multiple instance IDs. Separate multiple instance IDs with commas (,). A maximum of 50 instance IDs can be entered.

KeyPairName String Yes FinanceJoshuaV26

The name of the SSH key pair.

RegionId String Yes cn-hangzhou

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

Response parameters

Parameter Type Example Description
FailCount String 0

The number of instances from which the key pair fails to be detached.

KeyPairName String FinanceJoshuaV26

The name of the key pair.

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

The ID of the request.

Results Array

An array consisting of result data.

Result
Code String 200

The operation status code returned. 200 indicates that the operation is successful.

InstanceId String i-instanceid1

The ID of the instance.

Message String successful

The operation information returned. When the value of Code is 200, the value of Message becomes successful.

Success String true

Indicates whether the operation is successful.

TotalCount String 2

The total number of instances from which the key pair is detached.

Examples

Sample requests

https://ecs.aliyuncs.com/?Action=DetachKeyPair
&RegionId=cn-qingdao
&InstanceIds=["i-xxxxxxx", "i-yyyyyyy"]
&KeyPairName=test
&<Common request parameters>

Sample success responses

XML format

<DetachKeyPairResponse>
      <TotalCount>2</TotalCount>
      <RequestId>834B3E6B-2D1D-482F-81A4-810C327D4735</RequestId>
      <Results>
            <Result>
                  <Message>successful</Message>
                  <InstanceId>i-m5eg7be9ndloji64j***</InstanceId>
                  <Success>true</Success>
                  <Code>200</Code>
            </Result>
            <Result>
                  <Message>successful</Message>
                  <InstanceId>i-m5e25x2mwr0hk33dw***</InstanceId>
                  <Success>true</Success>
                  <Code>200</Code>
            </Result>
      </Results>
      <FailCount>0</FailCount>
</DetachKeyPairResponse>

JSON format

{
    "TotalCount": 2,
    "RequestId": "834B3E6B-2D1D-482F-81A4-810C327D4735",
    "Results": {
        "Result": [
            {
                "Message": "successful",
                "InstanceId": "i-m5eg7be9ndloji64j***",
                "Success": true,
                "Code": "200"
            },
            {
                "Message": "successful",
                "InstanceId": "i-m5e25x2mwr0hk33dw***",
                "Success": true,
                "Code": "200"
            }
        ]
    },
    "FailCount": 0
}

Error codes

HTTP status code Error code Error message Description
400 InvalidKeyPairName.NotFound The specified KeyPairName does not exist in our records. The error message returned because the specified KeyPairName parameter does not exist.
403 DependencyViolation.WindowsInstance The instance creating is windows, cannot use ssh key pair to login The error message returned because the specified instance is a Windows instance and does not support logons with SSH key pairs.
403 InstanceKeyPairLimitExceeded Exceeding the allowed amount of instance that an key pair can attach. The error message returned because the maximum number of key pairs that can be processed in a single request has been reached.
400 InvalidInstanceIds.ValueNotSupported The specified parameter InstanceIds is not valid. The error message returned because the specified InstanceIds parameter is invalid.

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