All Products
Search
Document Center

Resource Orchestration Service:ALIYUN::ECS::SSHKeyPair

Last Updated:Apr 08, 2025

ALIYUN::ECS::SSHKeyPair is used to create an SSH key pair or import an existing SSH key pair.

Syntax

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

Properties

Property

Type

Required

Editable

Description

Constraint

ResourceGroupId

String

No

Yes

The ID of the resource group to which the key pair belongs.

None.

KeyPairName

String

Yes

No

The name of the key pair.

The name must be 2 to 128 characters in length, and can contain letters, digits, colons (:), underscores (_), and hyphens (-). It must start with a letter and cannot start with http:// or https://.

PublicKeyBody

String

No

No

The public key of the key pair.

This property must be specified only when you import an existing key pair.

Tags

List

No

Yes

The tags.

You can add up to 20 tags.

For more information, see Tags properties.

Tags syntax

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

Tags properties

Property

Type

Required

Editable

Description

Constraint

Key

String

Yes

No

The key of the tag.

The key must be 1 to 128 characters in length, and cannot start with aliyun or acs:. It cannot contain http:// or https://.

Value

String

No

No

The value of the tag.

The value can be up to 128 characters in length, and cannot start with aliyun or acs:. It cannot contain http:// or https://.

Return values

Fn::GetAtt

  • KeyPairFingerPrint: the fingerprint of the key pair. The message-digest algorithm 5 (MD5) is used based on the public key fingerprint format defined in Request for Comments (RFC) 4716.

  • PrivateKeyBody: the private key of the key pair, which is an unencrypted Rivest-Shamir-Adleman (RSA) private key encoded with Privacy Enhanced Mail (PEM) in the PKCS#8 format. You can obtain the private key only when the key pair is created for the first time. If you import an existing public key, no private key information is available.

  • KeyPairName: the name of the key pair.

  • Arn: the Alibaba Cloud Resource Name (ARN).

Examples

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
{
  "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"
        ]
      }
    }
  }
}

For more information, see YAML examples.