Creating and importing SSH keys

POST /os-keypairs

Generates or imports a key pair.

Source: https://docs.openstack.org/api-ref/compute/index.html?expanded=create-or-import-keypair-detail#create-or-import-keypair

Request

Parameters

Name In Type Description
keypairs body array Array of keypair objects
keypair body object The keypair object.
name body string A name for the key pair 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 key pair is generated for you.
user_id (Optional) body string

The user ID for a key pair. This allows administrative users to upload keys for other users than themselves.

New in version 2.10

type (Optional) body string

The type of the key pair. Allowed values are ssh or x509.

New in version 2.2

Example

Generate a key pair:

# 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 key pair 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

Response

Parameters

Name In Type Description
keypairs body array Array of keypair objects
keypair body object The 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 this example, the offset value is -05:00.

name body string A name for the key pair which will be used to reference it later.
public_key body string The key pair public key.
fingerprint body string The fingerprint for the key pair.
user_id body string The user ID for a key pair.
private_key (Optional) body string If you do not provide a public key on create, a new key pair 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 key pair. Allowed values are ssh or x509.

New in version 2.2

Status codes

Success

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

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.

Example

Generate a key pair:

{
  "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 key pair:

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