Skip to content
  • Auto
  • Light
  • Dark

Create

Create a New SSH Key
client.gpuDroplets.account.keys.create(KeyCreateParams { name, public_key } body, RequestOptionsoptions?): KeyCreateResponse { ssh_key }
post/v2/account/keys

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.

ParametersExpand Collapse
body: KeyCreateParams { name, public_key }
name: string

A human-readable display name for this key, used to easily identify the SSH keys when they are displayed.

public_key: string

The entire public key string that was uploaded. Embedded into the root user's authorized_keys file if you include this key during Droplet creation.

ReturnsExpand Collapse
KeyCreateResponse { ssh_key }
ssh_key?: SSHKeys { name, public_key, id, fingerprint }
name: string

A human-readable display name for this key, used to easily identify the SSH keys when they are displayed.

public_key: string

The entire public key string that was uploaded. Embedded into the root user's authorized_keys file if you include this key during Droplet creation.

id?: number

A unique identification number for this key. Can be used to embed a specific SSH key into a Droplet.

fingerprint?: string

A 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.

Create a New SSH Key
import Gradient from '@digitalocean/gradient';

const client = new Gradient();

const key = await client.gpuDroplets.account.keys.create({
  name: 'My SSH Public Key',
  public_key:
    'ssh-rsa AEXAMPLEaC1yc2EAAAADAQABAAAAQQDDHr/jh2Jy4yALcK4JyWbVkPRaWmhck3IgCoeOO3z1e2dBowLh64QAM+Qb72pxekALga2oi4GvT+TlWNhzPH4V example',
});

console.log(key.ssh_key);
{
  "ssh_key": {
    "name": "My SSH Public Key",
    "public_key": "ssh-rsa AEXAMPLEaC1yc2EAAAADAQABAAAAQQDDHr/jh2Jy4yALcK4JyWbVkPRaWmhck3IgCoeOO3z1e2dBowLh64QAM+Qb72pxekALga2oi4GvT+TlWNhzPH4V example"
  }
}
Returns Examples
{
  "ssh_key": {
    "name": "My SSH Public Key",
    "public_key": "ssh-rsa AEXAMPLEaC1yc2EAAAADAQABAAAAQQDDHr/jh2Jy4yALcK4JyWbVkPRaWmhck3IgCoeOO3z1e2dBowLh64QAM+Qb72pxekALga2oi4GvT+TlWNhzPH4V example"
  }
}