Help Center > Elastic Cloud Server > API Reference > SSH Key Management > Creating and Importing an SSH Key Pair

Creating and Importing an SSH Key Pair

Function

This interface is used to create an SSH key pair or import a public key to generate a key pair.

After a private SSH key is created, download the private key to a local directory. Then, you can use this private key to log in to the ECS. To ensure ECS security, the private key can be downloaded only once. Keep it secure.

URI

  • URI format

    POST /v2/{project_id}/os-keypairs

  • Parameter description

    Name

    Mandatory

    Description

    project_id

    Yes

    Specifies the tenant ID.

Request

  • Parameter description
    NOTE:

    When creating an SSH key, you only need to configure name. When importing an SSH key, you must configure public_key.

    Name

    Mandatory

    Type

    Description

    keypair

    Yes

    Dictionary data structure [1]

    Specifies information about the created or imported SSH key.

[1] keypairs field data structure description

Name

Mandatory

Type

Description

public_key

No

String

Specifies the imported public key. The maximum size of the imported public key is 1024 bytes.

NOTE:

If the length of the public key to be imported exceeds 1024 bytes, the public key importing operation will fail.

name

Yes

String

Specifies the key pair name.

The new key pair name cannot be the same as an existing one.

  • Request example for creating an SSH key
    {
        "keypair": {
            "type": "ssh",
            "name": "demo"
        }
    }
  • Request example for importing an SSH key
    {
        "keypair": {
            "public_key": "ssh-rsaAAAAB3NzaC1yc2EAAAADAQABAAABAQDWNgTxQYeBzK9LYy4IakX7IsIl5j5zqR6BU2GJaEg3RK6dlS7rKFQhvy/V/1emK+GT/7P8up9VsMZ9Dx6PBOLow5p+2/wGsMlwDJpWiQ8zNnEMg+u/Ar/ZhYHAMyKEAOOJxIcnPoUgxfNdj/eiXV98AabsBdUA7QD30Og8F4Bmn2lii/WD9KbQQVjb7kbB3gNIJpGTUcoX73arorqkq/ppaLRmmwMJ7bTIGl8/0MWU2Dy+eTByOaDMb2htbB+j8ZXyEu7Oooy0NaSd+PNHv3PZ9OIVO7gd1lyoTRvCMK/F346+zmZtk5EASSOx5RifnSwk3NtugVjXs9GMJfFLBRibGenerated-by-Nova\\n\n",
            "type": "ssh",
            "name": "demo1"
        }
                        }

Response

  • Parameter description

    Name

    Type

    Description

    keypair

    Dictionary data structure [1]

    Specifies information about the SSH key.

[1] keypairs field data structure description

Name

Type

Description

fingerprint

String

Specifies fingerprint information about the key pair.

name

String

Specifies the key pair name.

public_key

String

Specifies information about the public key.

private_key

String

Specifies information about the private key.

  • The information about the private key is contained in the response for creating an SSH key.
  • The information about the private key is not contained in the response for importing an SSH key.

user_id

String

Specifies the ID of the user to which the key pair belongs.

  • Response example for creating an SSH key
    {
        "keypair": {
            "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDWNgTxQYeBzK9LYy4IakX7IsIl5j5zqR6BU2GJaEg3RK6dlS7rKFQhvy/V/1emK+GT/7P8up9VsMZ9Dx6PBOLow5p+2/wGsMlwDJpWiQ8zNnEMg+u/Ar/ZhYHAMyKEAOOJxIcnPoUgxfNdj/eiXV98AabsBdUA7QD30Og8F4Bmn2lii/WD9KbQQVjb7kbB3gNIJpGTUcoX73arorqkq/ppaLRmmwMJ7bTIGl8/0MWU2Dy+eTByOaDMb2htbB+j8ZXyEu7Oooy0NaSd+PNHv3PZ9OIVO7gd1lyoTRvCMK/F346+zmZtk5EASSOx5RifnSwk3NtugVjXs9GMJfFLBRib Generated-by-Nova\n",
            "private_key": "-----BEGIN RSA PRIVATE KEY-----\nMIIEpQIBAAKCAQEA1jYE8UGHgcyvS2MuCGpF+yLCJeY+c6kegVNhiWhIN0SunZUu\n6yhUIb8v1f9Xpivhk/+z/LqfVbDGfQ8ejwTi6MOaftv8BrDJcAyaVokPMzZxDIPr\nvwK/2YWBwDMihADjicSHJz6FIMXzXY/3ol1ffAGm7AXVAO0A99DoPBeAZp9pYov1\ng/Sm0EFY2+5Gwd4DSCaRk1HKF+92q6K6pKv6aWi0ZpsDCe20yBpfP9DFlNg8vnkw\ncjmgzG9obWwfo/GV8hLuzqKMtDWknfjzR79z2fTiFTu4HdZcqE0bwjCvxd+Ovs5m\nbZORAEkjseUYn50sJNzbboFY17PRjCXxSwUYmwIDAQABAoIBADNKQ+ywUA3YQLDA\nUqlZKOB09h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EgVelAP6DT6uePvzTFdSJ0dMQo\nzwgWNmm43CyoKW/rw8yIbtIQZKBfHudSNx72nSmnBKaf3QPB40xsCip90ZUTfZdn\nLJzX1t4clg1wNsN4mJDwiYM9k3rB/8EY1fh9gUYI84X6xFAHllkv0To=\n-----END RSA PRIVATE KEY-----\n",
            "user_id": "6fc0d2cbbfab40b199874b97097e913d",
            "name": "demo",
            "fingerprint": "fc:47:b5:c3:7d:25:32:d5:d2:0c:19:f9:62:ac:8c:5a",
            "type": "ssh"
        }
    }
  • Response example for importing an SSH key
    {
        "keypair": {
            "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDWNgTxQYeBzK9LYy4IakX7IsIl5j5zqR6BU2GJaEg3RK6dlS7rKFQhvy/V/1emK+GT/7P8up9VsMZ9Dx6PBOLow5p+2/wGsMlwDJpWiQ8zNnEMg+u/Ar/ZhYHAMyKEAOOJxIcnPoUgxfNdj/eiXV98AabsBdUA7QD30Og8F4Bmn2lii/WD9KbQQVjb7kbB3gNIJpGTUcoX73arorqkq/ppaLRmmwMJ7bTIGl8/0MWU2Dy+eTByOaDMb2htbB+j8ZXyEu7Oooy0NaSd+PNHv3PZ9OIVO7gd1lyoTRvCMK/F346+zmZtk5EASSOx5RifnSwk3NtugVjXs9GMJfFLBRib Generated-by-Nova\\n\n",
            "user_id": "6fc0d2cbbfab40b199874b97097e913d",
            "type": "ssh",
            "name": "demo1",
            "fingerprint": "fc:47:b5:c3:7d:25:32:d5:d2:0c:19:f9:62:ac:8c:5a"
        }
                        }

Returned Values

See General Request Returned Values.

Registration