Skip to main content

ssh_keys

Creates, updates, deletes, gets or lists a ssh_keys resource.

Overview

Namessh_keys
TypeResource
Iddigitalocean.compute.ssh_keys

Fields

The following fields are returned by SELECT queries:

A JSON object with the key set to ssh_key. The value is an ssh_key object containing the standard ssh_key attributes.

NameDatatypeDescription
idintegerA unique identification number for this key. Can be used to embed a specific SSH key into a Droplet.
namestringA human-readable display name for this key, used to easily identify the SSH keys when they are displayed. (example: My SSH Public Key)
fingerprintstringA unique identifier that differentiates this key from other keys using a format that SSH recognizes. The fingerprint is created when the key is added to your account. (example: 3b:16:bf:e4:8b:00:8b:b8:59:8c:a9:d3:f0:19:45:fa)
public_keystringThe entire public key string that was uploaded. Embedded into the root user's authorized_keys file if you include this key during Droplet creation. (example: ssh-rsa AEXAMPLEaC1yc2EAAAADAQABAAAAQQDDHr/jh2Jy4yALcK4JyWbVkPRaWmhck3IgCoeOO3z1e2dBowLh64QAM+Qb72pxekALga2oi4GvT+TlWNhzPH4V example)

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
ssh_keys_getselectssh_key_identifierTo get information about a key, send a GET request to /v2/account/keys/$KEY_ID or /v2/account/keys/$KEY_FINGERPRINT.
The response will be a JSON object with the key ssh_key and value an ssh_key object which contains the standard ssh_key attributes.
ssh_keys_listselectper_page, pageTo list all of the keys in your account, send a GET request to /v2/account/keys. The response will be a JSON object with a key set to ssh_keys. The value of this will be an array of ssh_key objects, each of which contains the standard ssh_key attributes.
ssh_keys_createinsertdata__public_key, data__nameTo add a new SSH public key to your DigitalOcean account, send a POST request to /v2/account/keys. Set the name attribute to the name you wish to use and the public_key attribute to the full public key you are adding.
ssh_keys_updatereplacessh_key_identifierTo update the name of an SSH key, send a PUT request to either /v2/account/keys/$SSH_KEY_ID or /v2/account/keys/$SSH_KEY_FINGERPRINT. Set the name attribute to the new name you want to use.
ssh_keys_deletedeletessh_key_identifierTo destroy a public SSH key that you have in your account, send a DELETE request to /v2/account/keys/$KEY_ID or /v2/account/keys/$KEY_FINGERPRINT.
A 204 status will be returned, indicating that the action was successful and that the response body is empty.

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
ssh_key_identifierEither the ID or the fingerprint of an existing SSH key. (example: 512189)
pageintegerWhich 'page' of paginated results to return. (example: 1)
per_pageintegerNumber of items returned per page (example: 2)

SELECT examples

To get information about a key, send a GET request to /v2/account/keys/$KEY_ID or /v2/account/keys/$KEY_FINGERPRINT.
The response will be a JSON object with the key ssh_key and value an ssh_key object which contains the standard ssh_key attributes.

SELECT
id,
name,
fingerprint,
public_key
FROM digitalocean.compute.ssh_keys
WHERE ssh_key_identifier = '{{ ssh_key_identifier }}' -- required;

INSERT examples

To add a new SSH public key to your DigitalOcean account, send a POST request to /v2/account/keys. Set the name attribute to the name you wish to use and the public_key attribute to the full public key you are adding.

INSERT INTO digitalocean.compute.ssh_keys (
data__public_key,
data__name
)
SELECT
'{{ public_key }}' --required,
'{{ name }}' --required
RETURNING
ssh_key
;

REPLACE examples

To update the name of an SSH key, send a PUT request to either /v2/account/keys/$SSH_KEY_ID or /v2/account/keys/$SSH_KEY_FINGERPRINT. Set the name attribute to the new name you want to use.

REPLACE digitalocean.compute.ssh_keys
SET
data__name = '{{ name }}'
WHERE
ssh_key_identifier = '{{ ssh_key_identifier }}' --required
RETURNING
ssh_key;

DELETE examples

To destroy a public SSH key that you have in your account, send a DELETE request to /v2/account/keys/$KEY_ID or /v2/account/keys/$KEY_FINGERPRINT.
A 204 status will be returned, indicating that the action was successful and that the response body is empty.

DELETE FROM digitalocean.compute.ssh_keys
WHERE ssh_key_identifier = '{{ ssh_key_identifier }}' --required;