0

Add an SSH key

by
Published Oct 17, 2025

Adds an SSH Key to your Account profile. > --- - __CLI__. ``` linode-cli sshkeys create \ --label "My SSH Key" \ --ssh_key "ssh-rsa AAAA_valid_public_ssh_key_123456785== user@their-computer" ``` [Learn more...](https://techdocs.akamai.com/cloud-computing/docs/getting-started-with-the-linode-cli) - __OAuth scopes__. ``` account:read_write ``` [Learn more...](https://techdocs.akamai.com/linode-api/reference/get-started#oauth)

Script linode Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Linode = {
3
  token: string;
4
};
5
/**
6
 * Add an SSH key
7
 * Adds an SSH Key to your Account profile.
8

9

10
>
11

12
---
13

14

15
- __CLI__.
16

17
    ```
18
    linode-cli sshkeys create \
19
  --label "My SSH Key" \
20
  --ssh_key "ssh-rsa AAAA_valid_public_ssh_key_123456785== user@their-computer"
21
    ```
22

23
    [Learn more...](https://techdocs.akamai.com/cloud-computing/docs/getting-started-with-the-linode-cli)
24

25
- __OAuth scopes__.
26

27
    ```
28
    account:read_write
29
    ```
30

31
    [Learn more...](https://techdocs.akamai.com/linode-api/reference/get-started#oauth)
32
 */
33
export async function main(
34
  auth: Linode,
35
  apiVersion: "v4" | "v4beta",
36
  body: { created?: string; id?: number; label?: string; ssh_key?: string },
37
) {
38
  const url = new URL(`https://api.linode.com/${apiVersion}/profile/sshkeys`);
39

40
  const response = await fetch(url, {
41
    method: "POST",
42
    headers: {
43
      "Content-Type": "application/json",
44
      Authorization: "Bearer " + auth.token,
45
    },
46
    body: JSON.stringify(body),
47
  });
48
  if (!response.ok) {
49
    const text = await response.text();
50
    throw new Error(`${response.status} ${text}`);
51
  }
52
  return await response.json();
53
}
54