ALIYUN::ECS::SSHKeyPair类型用于创建SSH密钥对或导入已有的SSH密钥对。

语法

{
  "Type": "ALIYUN::ECS::SSHKeyPair",
  "Properties": {
    "ResourceGroupId": String,
    "KeyPairName": String,
    "PublicKeyBody": String,
    "Tags": List
  }
}

属性

属性名称类型必须允许更新描述约束
ResourceGroupIdString实例所在的资源组ID。
KeyPairName String 密钥对的名称。 长度为2~128个字符。必须以英文字母或汉字开头,不能以http://https://开头。可包含英文字母、汉字、数字、半角冒号(:)、下划线(_)和短划线(-)。
PublicKeyBody String 密钥对的公钥内容。 仅在导入密钥对时需要指定该参数。
TagsList标签。最多支持添加20个标签。

更多信息,请参见Tags属性

Tags语法

"Tags": [
  {
    "Key": String,
    "Value": String
  }
]  

Tags属性

属性名称类型必须允许更新描述约束
KeyString标签键。长度为1~128个字符,不能以aliyunacs:开头,不能包含http://或者https://
ValueString标签值。长度为0~128个字符,不能以aliyunacs:开头,不能包含http://或者https://

返回值

Fn::GetAtt

  • KeyPairFingerPrint:密钥对的指纹。根据RFC4716定义的公钥指纹格式,采用MD5信息摘要算法。
  • PrivateKeyBody:密钥对的私钥。未加密的PEM编码PKCS#8格式的RSA私钥内容。只有在第一次创建完成后有唯一的机会获取密钥对的私钥。如果是导入已有公钥,则不会有私钥信息。
  • KeyPairName:密钥对名称。

示例

  • YAML格式

    ROSTemplateFormatVersion: '2015-09-01'
    Parameters: {}
    Resources:
      SSHKeyPair:
        Type: ALIYUN::ECS::SSHKeyPair
        Properties:
          KeyPairName:
            Fn::Sub: ess-${ALIYUN::StackId}
    Outputs:
      KeyPairFingerPrint:
        Description: 'The fingerprint of the key pair. The public key fingerprint format defined in RFC4716: MD5 message digest algorithm. '
        Value:
          Fn::GetAtt:
            - SSHKeyPair
            - KeyPairFingerPrint
      KeyPairName:
        Description: SSH Key pair name.
        Value:
          Fn::GetAtt:
            - SSHKeyPair
            - KeyPairName
      PrivateKeyBody:
        Description: 'The private key of the key pair. Content of the RSA private key in the PKCS#8 format of the unencrypted PEM encoding. Refer to: https://www.openssl.org/docs/apps/pkcs8.html.User only can get the private key one time when and only when SSH key pair is created.'
        Value:
          Fn::GetAtt:
            - SSHKeyPair
            - PrivateKeyBody
  • JSON格式

    {
      "ROSTemplateFormatVersion": "2015-09-01",
      "Parameters": {
      },
      "Resources": {
        "SSHKeyPair": {
          "Type": "ALIYUN::ECS::SSHKeyPair",
          "Properties": {
            "KeyPairName": {
              "Fn::Sub": "ess-${ALIYUN::StackId}"
            }
          }
        }
      },
      "Outputs": {
        "KeyPairFingerPrint": {
          "Description": "The fingerprint of the key pair. The public key fingerprint format defined in RFC4716: MD5 message digest algorithm. ",
          "Value": {
            "Fn::GetAtt": [
              "SSHKeyPair",
              "KeyPairFingerPrint"
            ]
          }
        },
        "KeyPairName": {
          "Description": "SSH Key pair name.",
          "Value": {
            "Fn::GetAtt": [
              "SSHKeyPair",
              "KeyPairName"
            ]
          }
        },
        "PrivateKeyBody": {
          "Description": "The private key of the key pair. Content of the RSA private key in the PKCS#8 format of the unencrypted PEM encoding. Refer to: https://www.openssl.org/docs/apps/pkcs8.html.User only can get the private key one time when and only when SSH key pair is created.",
          "Value": {
            "Fn::GetAtt": [
              "SSHKeyPair",
              "PrivateKeyBody"
            ]
          }
        }
      }
    }

更多示例,请参见创建单个ECS实例、创建SSH密钥对和绑定SSH密钥和ECS实例的组合示例:JSON示例YAML示例