Attach an SSH key

Add the key to the root user's authorized_keys on running servers in this zone. We add it in the background, usually within seconds. Each server records ssh_key_attached or ssh_key_attach_failed in its events. The key shows in the server's ssh_keys at once, and a later restore or rescue keeps it. Attaching a key a server already has adds it again.

POST https://{availability_zone}.betterstackcloud.com/v1/ssh-keys/{slug}/attach
slug string required

The slug of the key. Dots are part of the slug.

team_id string

The ID of the team that owns the key. Send it when more than one of your teams has a key with this slug.

Authorization string required

Bearer $TOKEN

Content-Type string

application/json

server_ids array of strings

The IDs of the servers to attach the key to. When one of them doesn't exist or can't get the key now, the request is refused and nothing changes. A repeated ID counts once.

all boolean

Whether to attach the key to every server in this zone. A server that can't get the key now is skipped and listed with a reason. Send either all or server_ids, never both.

202 Accepted
{
  "servers": {
    "queued": [
      "example"
    ],
    "skipped": [
      {
        "server_id": "123456789",
        "reason": "kubernetes_managed"
      }
    ]
  }
}

Returns the SSH key.

servers object

What we did with each server.

servers.queued array of strings

The IDs of the servers we're changing.

servers.skipped array of objects

The servers we skipped with all, each with a reason, empty when you send server_ids.

servers.skipped[].server_id string

The ID of the skipped server.

servers.skipped[].reason string

Why we skipped the server.
Valid values:
kubernetes_managed: The server is a Kubernetes worker node.
locked: The server is locked.
server_not_running: The server isn't running.