0

Update an SSH key

by
Published Oct 17, 2025

Updates an SSH Key that you have permission to `read_write`. Only SSH key labels can be updated. > --- - __CLI__. ``` linode-cli sshkeys update 42 \ --label "my laptop" ``` [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
 * Update an SSH key
7
 * Updates an SSH Key that you have permission to `read_write`.
8

9
Only SSH key labels can be updated.
10

11

12
>
13

14
---
15

16

17
- __CLI__.
18

19
    ```
20
    linode-cli sshkeys update 42 \
21
  --label "my laptop"
22
    ```
23

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

26
- __OAuth scopes__.
27

28
    ```
29
    account:read_write
30
    ```
31

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

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