- Documentation
Elastic Compute Service
Elastic Compute Service
API Reference
Key pairs
DetachKeyPair - Disassociates key pairs
Key pairs
DetachKeyPair - Disassociates key pairs
DetachKeyPair - Disassociates key pairs
Call the DetachKeyPair operation to disassociate a key pair from one or more Linux instances.
Request description
- You can disassociate a key pair from an instance only when the instance has the password plugin installed. Please install the password plugin first.
- Currently, you can disassociate a key pair from an instance only when the instance is in the Running or Stopped status.
- After a key pair is disassociated from an instance, it is no longer valid in that instance. If the instance supports password login, you can still log in with your password after disassociation. Otherwise, you need to re-associate a key pair or reset the password to log in again. Proceed with caution.
- After you disassociate the key pair, you need to restart the instances for the new settings to take effect.
Debugging
API Explorer
You can initiate calls online through API Explorer without paying attention to the signature generation process and quickly obtain the call results.
Request parameters
Only the request parameters specific to this operation and some common parameters are listed below. For details, refer to Common parameters. Action string required Sample value: DetachKeyPair
The action that you want to perform. Value: DetachKeyPair.
Version stringrequired Sample value: 2020-04-01
The API version. Valid value: 2020-04-01.
ClientToken string Optional Sample value: 333456899ff****
ClientToken is used to ensure the idempotency of the request. The client can automatically generate a token, but you need to ensure that it is unique across requests. This prevents duplicate operations caused by multiple retries when the API request times out or an internal server error occurs.
Value: Only ASCII characters are supported. The length is no more than 64 ASCII characters.
InstanceIds.N string[] required Sample value: InstanceIds.1=i-ahipakt2gcg95jpv****&InstanceIds.2=i-ahipakt2gdg95lbe****
The instance ID. A maximum of 100 instance IDs are supported.
- Parameter - N: specifies the serial number of the instance.
- Separate multiple instance IDs with ampersands (&).
KeyPairId string Optional Sample value: kp-ybqcopwrdwl8j1******
The unique ID of the key pair. You can call the DescribeKeyPairs operation to query and obtain it. - The KeyPairName and KeyPairId parameters cannot both be empty.
- If the KeyPairName and KeyPairId parameters are configured at the same time, KeyPairId takes precedence.
KeyPairName string Optional Sample value: ssh_key_pair
The name of the key pair.
- The KeyPairName and KeyPairId parameters cannot both be empty.
- If the KeyPairName and KeyPairId parameters are configured at the same time, KeyPairId takes precedence.
Response parameters
Only the response parameters specific to this operation are listed below. For more information, please refer to Response Structure. tip
The following error codes for the operation are returned only when you specify invalid request parameter values. If you specify valid request parameter values, no error code is displayed, and status code 200 is returned. However, this does not mean all key pairs are successfully operated on. To check the operation result of one key pair, refer to the following response parameters. OperationDetails object[] Sample value: --
The operation details.
Error object Sample value: --
The error message for the key pair being operated on.
Code string Sample value: InvalidInstance.NotFound
The error code for the failure of a specific request during batch operations. Valid values:
- InvalidInstance.NotFound: The specified instance does not exist.
- InvalidKeyPairForWindows.Unsupported: The specified instance is based on the Windows operating system and does not support key pairs.
- InvalidResetAuthenticationAgent.NotFound: The specified reset-authentication plug-in does not exist.
- InvalidInstanceStatus: The current status of the instance does not support this operation.
- FlowLimitExceeded: You have exceeded the rate limit for resource requests.
tip
Each Code corresponds to a Message in sequence.
Message string Sample value: The specified instance does not exist.
The error information for the failure of a specific request during batch operations. Valid values:
- The specified instance does not exist.
- The OSType of this specified instance is Windows, which does not support key pairs.
- The specified reset-authentication agent does not install on the instance.
- The status of the specified instance does not support this request.
- You've reached the limit on request rate of resources.
tip
Each Code corresponds to a Message in sequence.
InstanceId string Sample value: i-ybo349sxoncm9t******
The ID of the instance on which the operation is performed.
Sample request
Sample response
Error codes
The table below lists the business-related error codes of the operation. For more information, refer to Common error codes.
Last updated: 2026.06.24 17:17:26