- 文档首页
云服务器
云服务器ECS
API参考
密钥对
AttachKeyPair - 绑定密钥对
AttachKeyPair - 绑定密钥对
调用 AttachKeyPair 绑定一个密钥对到一台或多台Linux实例。
请求说明
- 当前密钥对仅支持绑定 运行中 、 已停止 两种状态的实例。
- 如果您已通过控制台为实例绑定密钥对,本次新绑定的密钥对会覆盖已有密钥对,但对您手动在实例内部添加的密钥对无影响。
- 绑定密钥对后需重启实例,密钥对方可生效。如果您的实例已设置密码登录,绑定密钥对并重启后,密码登录方式自动失效。
调试
API Explorer
您可以通过 API Explorer 在线发起调用,无需关注签名生成过程,快速获取调用结果。
请求参数
下表仅列出该接口特有的请求参数和部分公共参数。更多信息请见公共参数。 Action string 必选 示例值:AttachKeyPair
要执行的操作,取值:AttachKeyPair。
Version string 必选 示例值:2020-04-01
API的版本,取值:2020-04-01。
ClientToken string 可选 示例值:333456899ff****
保证请求幂等性。由客户端自动生成一个参数值,确保不同请求间该参数值唯一,避免当调用API超时或服务器内部错误时,客户端多次重试导致重复性操作。
取值:仅支持ASCII字符,且不能超过64个字符。
InstanceIds.N string[] 必选 示例值:InstanceIds.1=i-ahipakt2gcg95jpv****&InstanceIds.2=i-ahipakt2gdg95lbe****
实例ID,最多支持100个。
KeyPairId string 可选 示例值:kp-ybqcopwrdwl8j1******
- KeyPairName与KeyPairId不允许同时为空。
- 如果同时设置了KeyPairName与KeyPairId,则优先生效KeyPairId。
KeyPairName string 可选 示例值:ssh_key_pair
密钥对名称。
- KeyPairName与KeyPairId不允许同时为空。
- 如果同时设置了KeyPairName与KeyPairId,则优先生效KeyPairId。
返回参数
下表仅列出本接口特有的返回参数。更多信息请参见返回结构。 说明
仅当请求参数输入不合法时提示下文中的接口错误码。若请求参数输入无误,将不会提示接口错误码,且接口的返回状态码将为200,但这并不代表对所有密钥对的操作均已成功,单个密钥对的操作结果请参见如下返回参数中的信息。 OperationDetails object[] 示例值:--
操作详情。
Error object 示例值:--
操作的密钥对错误信息。
Code string 示例值:InvalidInstance.NotFound
批量操作时具体单个请求失败的错误码,取值:
- InvalidInstance.NotFound:指定的实例不存在。
- InvalidKeyPairForWindows.Unsupported:指定的实例是Windows操作系统,不支持密钥对。
- InvalidResetAuthenticationAgent.NotFound:指定的密码重置插件不存在。
- InvalidInstanceStatus :当前的实例状态不支持此操作。
- FlowLimitExceeded:您已超过资源请求限速。
Message string 示例值:The specified instance does not exist.
批量操作时具体单个请求失败的错误信息,取值:
- 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 reach the limit on request rate of resources.
InstanceId string 示例值:i-ybo349sxoncm9t******
操作的实例ID。
请求示例
GET /?Action=AttachKeyPair&Version=2020-04-01&KeyPairName=ssh_key_pair1&InstanceIds.1=i-ahipakt2gcg95jpv****&InstanceIds.2=i-ahipakt2gdg95lbe**** HTTP/1.1
Host: ecs.cn-beijing.volcengineapi.com
返回示例
"RequestId": "202106111445100102252431000052****",
"Action": "AttachKeyPair",
"Version": "2020-04-01",
"InstanceId": "i-ahipakt2gcg95jpv****",
"InstanceId": "i-ahipakt2gdg95lbe****",
"Code": "InvalidInstance.NotFound",
"Message": "The specified instance does not exist."
错误码
下表为您列举了该接口与业务逻辑相关的错误码。公共错误码请参见公共错误码文档。
最近更新时间:2025.09.04 16:59:40