12.2. Creating and importing SSH keys

POST /os-keypairs

Generates or imports a keypair.

Source: https://docs.openstack.org/api-ref/compute/#create-or-import-keypair

12.2.1. Request

Name In Type Description
keypair body object Keypair object
name body string A name for the keypair which will be used to reference it later.
public_key (Optional) body string The public ssh key to import. If you omit this value, a keypair is generated for you.
type (Optional) body string

The type of the keypair. Allowed values are ssh or x509.

New in version 2.2

user_id (Optional) body string

The user_id for a keypair. This allows administrative users to upload keys for other users than themselves.

New in version 2.10

12.2.1.1. Example

Generate a keypair:

# curl -ks -X POST -H 'Content-Type: application/json' -H 'X-Auth-Token: gAAAAA<...>' -d '
{
    "keypair": {
        "name": "key2"
    }                
}' https://<node_IP_addr>:8774/v2.1/f5d834d636c642c7bfe8af86139c6f26/os-keypairs

Import a public keypair with an optional description in VSTOR-KEY-DESC:

# curl -ks -X POST -H 'Content-Type: application/json' -H 'X-Auth-Token: gAAAAA<...>' -d '
{
    "keypair": {
        "name": "key3",
        "public_key": "ssh-rsa AAAA<...> VSTOR-KEY-DESC:Key3 description"
    }
}' https://<node_IP_addr>:8774/v2.1/f5d834d636c642c7bfe8af86139c6f26/os-keypairs

12.2.2. Response

Name In Type Description
keypair body object Keypair object
created_at body string

The date and time when the resource was created. The date and time stamp format is ISO 8601

CCYY-MM-DDThh:mm:ss±hh:mm

For example, 2015-08-27T09:49:58-05:00. The ±hh:mm value, if included, is the time zone as an offset from UTC. In the previous example, the offset value is -05:00.

name body string A name for the keypair which will be used to reference it later.
public_key body string The keypair public key.
fingerprint body string The fingerprint for the keypair.
user_id body string The user_id for a keypair.
private_key (Optional) body string If you do not provide a public key on create, a new keypair will be built for you, and the private key will be returned during the initial create call. Make sure to save this, as there is no way to get this private key again in the future.
type body string

The type of the keypair. Allowed values are ssh or x509.

New in version 2.2

12.2.2.1. Status codes

12.2.2.1.1. Success

Code Reason
200 - OK Request was successful.
201 - Created Resource was created and is ready to use.

12.2.2.1.2. Error

Code Reason
400 - Bad Request Some content in the request was invalid.
401 - Unauthorized User must authenticate before making a request.
403 - Forbidden Policy does not allow current user to do this operation.
409 - Conflict This operation conflicted with another operation on this resource.

12.2.2.2. Example

Generate a keypair:

{
  "keypair": {
    "public_key": "ssh-rsa AAAA<...> Generated-by-Nova",
    "private_key": "-----BEGIN RSA PRIVATE KEY-----\nMII<...>\n-----END RSA PRIVATE KEY-----\n",
    "user_id": "eb481bff7b7c4ec6a686646957d8064b",
    "name": "key2",
    "created_at": "2020-02-12T09:23:35.524428",
    "fingerprint": "dd:91:ef:1a:05:0b:17:57:bd:46:cb:69:53:63:62:f4",
    "type": "ssh"
  }
}

Import a public keypair:

{
  "keypair": {
    "public_key": "ssh-rsa AAAA<...>",
    "user_id": "eb481bff7b7c4ec6a686646957d8064b",
    "name": "key3",
    "created_at": "2020-02-12T09:22:57.508566",
    "fingerprint": "1e:2c:9b:56:79:4b:45:77:f9:ca:7a:98:2c:b0:d5:3c",
    "type": "ssh"
  }
}