---
title: "Add a public key on behalf of a user"
method: POST
path: "/admin/users/{username}/keys"
tags: ["admin"]
---

# Add a public key on behalf of a user

`POST /admin/users/{username}/keys`

## Path parameters

- `username` string, required

## Request body

- CreateKeyOption — CreateKeyOption options when creating a key
  - `key` string, required — An armored SSH key to add
  - `read_only` boolean — Describe if the key has only read access or read/write
  - `title` string, required — Title of the key to add

## Response `201`

PublicKey

- PublicKey — PublicKey publickey is a user key to push code to repository
  - `created_at` string, date-time — Created is the time when the key was added
  - `fingerprint` string — Fingerprint is the key's fingerprint
  - `id` integer — ID is the unique identifier for the public key
  - `key` string — Key contains the actual SSH public key content
  - `key_type` string — KeyType indicates the type of the SSH key
  - `last_used_at` string, date-time — Updated is the time when the key was last used
  - `read_only` boolean — ReadOnly indicates if the key has read-only access
  - `title` string — Title is the human-readable name for the key
  - `url` string — URL is the API URL for this key
  - `user` User — User represents a user
    - `active` boolean — Is user active
    - `avatar_url` string — URL to the user's avatar
    - `created` string, date-time
    - `description` string — the user's description
    - `email` string, email
    - `followers_count` integer — user counts
    - `following_count` integer
    - `full_name` string — the user's full name
    - `html_url` string — URL to the user's gitea page
    - `id` integer — the user's id
    - `is_admin` boolean — Is the user an administrator
    - `language` string — User locale
    - `last_login` string, date-time
    - `location` string — the user's location
    - `login` string — login of the user, same as `username`
    - `login_name` string — identifier of the user, provided by the external authenticator (if configured)
    - `prohibit_login` boolean — Is user login prohibited
    - `restricted` boolean — Is user restricted
    - `source_id` integer — The ID of the user's Authentication Source
    - `starred_repos_count` integer
    - `visibility` 'public' | 'limited' | 'private' — User visibility level option: public, limited, private
    - `website` string — the user's website

## Other responses

- `403` — APIForbiddenError is a forbidden error response
- `422` — APIValidationError is error format response related to input validation

---

[API](https://skmtc.net/gitea/apis/gitea-api.md) · [All operations](https://skmtc.net/gitea/apis/gitea-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/gitea/gitea-api/versions/350de506cefa/schema)
