# POST /users/{name}/ssh-keys

First published 3 Oct 2026 (release 0.1.0) · Unchanged since publication

UrbeStack release 0.2.35 API operation in the users group.

Add an SSH public key for a customer

- Who may call it: administrator, reseller, customer
- Token scope, any of: users, all
- Answers: 201 Created

Administrators, the customer's reseller and the customer can add a key. The target needs a Linux account. Administrator accounts lack one.

Supply one public key line in ssh-keygen format, with the key type, key data and an optional comment. Omit authorized_keys options. UrbeStack trims surrounding whitespace and returns 400 if key is empty or contains multiple lines. UrbeStack rejects DSA keys and validates public keys with ssh-keygen -l.

A label must contain 1 to 64 printable ASCII characters. If label is omitted or empty, UrbeStack uses up to 64 printable ASCII characters from the key comment, or the key type if the comment yields no label. Each customer can keep up to ssh_keys_max keys, which defaults to 20. A fingerprint already on that customer's list returns 409.

The response contains the added key in key. UrbeStack immediately updates the customer's file under ssh_keys_dir, /etc/urbestack/ssh/keys/<name> by default. sshd reads that file alongside the customer's .ssh/authorized_keys.

## As a command

- [urbestack-ssh-key-add](https://urbestack.com/docs/commands/urbestack-ssh-key-add.md): Adds an SSH public key to a customer's list.

## Parameters

- `name` (path, Username, required)

## Request body

JSON, the type [SshKeyCreate](https://urbestack.com/docs/api/types/SshKeyCreate.md).

- `key` (string, up to 16384 characters, required): One public key in the format produced by ssh-keygen. Supply only the key type, key data and optional comment.
- `label` (string, up to 64 characters): Optional label of 1 to 64 printable characters. If omitted, the label defaults to the key's comment if present, or the key type otherwise.

## Example

Set $API to the base URL and $TOKEN to the token, as the [API overview](https://urbestack.com/docs/api.md) shows.

```
curl -sS -X POST "$API/users/alice/ssh-keys" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "key": "panel.port",
    "label": "my laptop"
  }'
```

Response, 201 Created:

```
{
  "key": {
    "created_at": "2026-09-09T10:15:00Z",
    "fingerprint": "text",
    "id": 1,
    "key": "panel.port",
    "label": "my laptop",
    "type": "rebuild",
    "user": "alice"
  }
}
```

## Errors

- 400: --key-stdin is required: the key comes on standard input
- 400: --user is required
- 400: <user.name> has <n> SSH keys, the limit: remove one first
- 400: <user.name> is an administrator: administrators have no system account, so no SSH keys here
- 400: Invalid label: 1 to 64 printable ASCII characters
- 400: Invalid username: 2 to 32 lowercase letters, digits or underscores, starting with a letter
- 400: Paste one public key, on one line
- 400: Username '<value>' is reserved
- 400: key is required: one public key, as ssh-keygen writes it
- 401: Authentication required
- 404: User '<user>' not found
- 409: This key is on the list already, as '<dup.label>'
