创建和导入ssh密钥对-九游平台
功能介绍
创建和导入ssh密钥对
调用方法
请参见。
uri
post /v3/{project_id}/keypairs
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
string |
项目id |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
x-auth-token |
是 |
string |
用户token。 通过调用iam服务获取用户token接口获取(响应消息头中x-subject-token的值)。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
keypair |
是 |
object |
创建密钥对请求体请求参数 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
name |
是 |
string |
ssh密钥对的名称。
|
type |
否 |
string |
ssh密钥对的类型。ssh或x509。 |
public_key |
否 |
string |
导入公钥的字符串信息。 |
scope |
否 |
string |
租户级或者用户级。domain或user。 |
user_id |
否 |
string |
ssh密钥对所属的用户信息 |
key_protection |
否 |
object |
ssh密钥对私钥托管与保护。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
private_key |
否 |
string |
导入ssh密钥对的私钥。 |
encryption |
是 |
object |
对私钥进行加密存储的方式。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
type |
是 |
string |
取值范围:“kms”或“default”。
|
kms_key_name |
否 |
string |
kms密钥的名称。
|
kms_key_id |
否 |
string |
kms密钥的id。
|
响应参数
状态码: 200
参数 |
参数类型 |
描述 |
---|---|---|
keypair |
object |
ssh密钥对信息详情 |
参数 |
参数类型 |
描述 |
---|---|---|
name |
string |
ssh密钥对的名称 |
type |
string |
ssh密钥对的类型。ssh或x509。 |
public_key |
string |
ssh密钥对对应的publickey信息 |
private_key |
string |
ssh密钥对对应的privatekey信息
|
fingerprint |
string |
ssh密钥对应指纹信息 |
user_id |
string |
ssh密钥对所属的用户信息 |
状态码: 400
参数 |
参数类型 |
描述 |
---|---|---|
error_code |
string |
错误码 |
error_msg |
string |
错误描述 |
请求示例
{ "keypair" : { "name" : "demo2" } }
响应示例
状态码: 200
请求已成功
{ "keypair" : { "name" : "demo", "type" : "ssh", "public_key" : "ssh-rsa aaaab3nzac1yc2eaaaadaqab...", "private_key" : "-----begin rsa private key-----...", "fingerprint" : "49:ef:73:2b:9b:7f:2e:0c:58:d3:e3:42:8e:28:04:3b", "user_id" : "e4f380899b1248918f3d37098dc63746" } }
状态码: 400
error response
{ "error_code" : "kps.xxx", "error_msg" : "xxx" }
sdk代码示例
sdk代码示例如下。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
packagecom.huaweicloud.sdk.test; importcom.huaweicloud.sdk.core.auth.icredential; importcom.huaweicloud.sdk.core.auth.basiccredentials; importcom.huaweicloud.sdk.core.exception.connectionexception; importcom.huaweicloud.sdk.core.exception.requesttimeoutexception; importcom.huaweicloud.sdk.core.exception.serviceresponseexception; importcom.huaweicloud.sdk.kps.v3.region.kpsregion; importcom.huaweicloud.sdk.kps.v3.*; importcom.huaweicloud.sdk.kps.v3.model.*; publicclass createkeypairsolution{ publicstaticvoidmain(string[]args){ // the ak and sk used for authentication are hard-coded or stored in plaintext, which has great security risks. it is recommended that the ak and sk be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // in this example, ak and sk are stored in environment variables for authentication. before running this example, set environment variables cloud_sdk_ak and cloud_sdk_sk in the local environment stringak=system.getenv("cloud_sdk_ak"); stringsk=system.getenv("cloud_sdk_sk"); stringprojectid="{project_id}"; icredentialauth=newbasiccredentials() .withprojectid(projectid) .withak(ak) .withsk(sk); kpsclientclient=kpsclient.newbuilder() .withcredential(auth) .withregion(kpsregion.valueof(" |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import basiccredentials from huaweicloudsdkkps.v3.region.kps_region import kpsregion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkkps.v3 import * if __name__ == "__main__": # the ak and sk used for authentication are hard-coded or stored in plaintext, which has great security risks. it is recommended that the ak and sk be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # in this example, ak and sk are stored in environment variables for authentication. before running this example, set environment variables cloud_sdk_ak and cloud_sdk_sk in the local environment ak = os.environ["cloud_sdk_ak"] sk = os.environ["cloud_sdk_sk"] projectid = "{project_id}" credentials = basiccredentials(ak, sk, projectid) client = kpsclient.new_builder() \ .with_credentials(credentials) \ .with_region(kpsregion.value_of(" |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
packagemain import( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" kps"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/kps/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/kps/v3/model" region"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/kps/v3/region" ) funcmain(){ // the ak and sk used for authentication are hard-coded or stored in plaintext, which has great security risks. it is recommended that the ak and sk be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // in this example, ak and sk are stored in environment variables for authentication. before running this example, set environment variables cloud_sdk_ak and cloud_sdk_sk in the local environment ak:=os.getenv("cloud_sdk_ak") sk:=os.getenv("cloud_sdk_sk") projectid:="{project_id}" auth:=basic.newcredentialsbuilder(). withak(ak). withsk(sk). withprojectid(projectid). build() client:=kps.newkpsclient( kps.kpsclientbuilder(). withregion(region.valueof(" |
更多编程语言的sdk代码示例,请参见的代码示例页签,可生成自动对应的sdk代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
请求已成功 |
400 |
error response |
错误码
请参见。
相关文档
意见反馈
文档内容是否对您有帮助?
如您有其它疑问,您也可以通过华为云社区问答频道来与我们联系探讨