> For the complete documentation index, see [llms.txt](https://icij.gitbook.io/datashare/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://icij.gitbook.io/datashare/server-mode/manage-users-from-the-cli.md).

# Manage users from the CLI

Create and delete Datashare users with the datashare user subcommands.

The `datashare user` subcommands let you provision and remove users directly from the command line, without writing SQL or Redis commands by hand:

| Subcommand    | Description                                      |
| ------------- | ------------------------------------------------ |
| `user create` | Create a Datashare user                          |
| `user delete` | Delete a Datashare user and all their owned data |

Run these commands with the same data-store settings as your server (`--dataSourceUrl`, and `--redisAddress` if your deployment uses Redis) so they operate on the same user inventory.

In server mode, the same accounts can also be created, edited and deleted from the interface: see [Manage users from the UI](/datashare/server-mode/manage-users-from-the-ui.md).

## Create a user

```bash
datashare user create alice --email alice@example.org
```

The login can be passed as a positional argument (as above) or with `--login`. Useful options:

| Option            | Description                                       |
| ----------------- | ------------------------------------------------- |
| `--email`         | RFC 5322 email address                            |
| `--name`          | Display name (default: login)                     |
| `--password`      | Password, for the `local` provider                |
| `--provider`      | `local`, `oauth` or `external` (default: `local`) |
| `--groups`        | Comma-separated project names the user can access |
| `--if-not-exists` | Idempotent: exit 0 if the user already exists     |
| `--json`          | Emit a JSON result on stdout                      |
| `--no-input`      | Disable interactive prompts                       |

For example, to create a local user with a password and access to two projects:

```bash
datashare user create alice \
    --email alice@example.org \
    --password "$PW" \
    --groups project1,project2
```

Or to provision a user authenticated by an external identity provider (see [OAuth2](/datashare/server-mode/user-management/oauth2.md)):

```bash
datashare user create alice --email alice@example.org --provider oauth --no-input
```

{% hint style="info" %}
Prefer passing the password through an environment variable (as in the example above) rather than typing it literally, so it doesn't end up in your shell history.
{% endhint %}

With Docker Compose, prefix the command with the web container's entrypoint:

```bash
docker compose exec datashare_web /entrypoint.sh \
  user create alice \
  --email alice@example.org \
  --dataSourceUrl 'jdbc:postgresql://postgres/datashare?user=<username>&password=<password>'
```

## Delete a user

```bash
datashare user delete alice --yes
```

{% hint style="danger" %}
Deleting a user removes the user **and all their owned data**. This cannot be undone.
{% endhint %}

| Option        | Description                                  |
| ------------- | -------------------------------------------- |
| `--yes`, `-y` | Skip the confirmation prompt                 |
| `--if-exists` | Idempotent: exit 0 if the user doesn't exist |
| `--json`      | Emit a JSON result on stdout                 |
| `--no-input`  | Disable interactive prompts (forces `--yes`) |

## Scripting

All `user` subcommands are script-friendly: combine `--json` (machine-readable output), `--no-input` (no prompts) and the idempotency flags (`--if-not-exists` / `--if-exists`) to write provisioning scripts that can safely be re-run:

```bash
datashare user create alice --email alice@example.org --if-not-exists --no-input --json
```

## Related pages

* [User management](/datashare/server-mode/user-management.md) for choosing an authentication method and the user record format.
* [Manage projects from the CLI](/datashare/server-mode/manage-projects-from-the-cli.md) for granting users a role on a project.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://icij.gitbook.io/datashare/server-mode/manage-users-from-the-cli.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
