> ## Documentation Index
> Fetch the complete documentation index at: https://anaconda.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Service accounts and tokens

You can manage channel service accounts and authorization tokens in Package Security Manager from the command line. For general information about service accounts, see [Channel service accounts](https://anaconda.com/docs/psm-on-prem/6.8.0/admin/advanced/channel_service_account.md). For general information about tokens, see [Authorization tokens](https://anaconda.com/docs/psm-on-prem/6.8.0/user/auth_token.md).

> [!NOTE]
>
> The commands on this page prompt for your Package Security Manager username and password each time you run them, even if you're already logged in with `conda repo login`. Because of this, you can't run them in non-interactive scripts.

## Authorization tokens

Authorization tokens provide others with access to private or authenticated channels or with a specific set of permissions within Package Security Manager.

### Viewing scopes

Scopes are fine-grained permissions you can embed within a token to limit the actions that can be performed. To view a list of available scopes:

```sh theme={null}
conda repo auth --list-scopes
```

### Creating a scope token

To generate a new user authorization token:

```sh theme={null}
conda repo auth --create --name <NAME> --scopes <SCOPE> --scopes <SCOPE>
```

Comments

Replace \<NAME> with a name for your token.\\

Replace \<SCOPE> with a valid scope (repeat `--scopes` for multiple scopes).

### Removing a user authorization token

```sh theme={null}
conda repo auth --remove <TOKEN_ID>
```

Comments

Replace \<TOKEN\_ID> with the token you want to remove.

## Channel service accounts

> [!NOTE]
>
> Channel service accounts are available in Package Security Manager version 6.6.5 and later.

### Listing all channel service accounts

```sh theme={null}
conda repo service-accounts --channel <CHANNEL_NAME> --list-user-ids
```

Comments

Replace \<CHANNEL\_NAME> with the name of your channel.

### Creating a service account token

Creating tokens for a service account provides the account with specified permissions to act on specified channels.

> [accordion] Create a channel service account token
>
> ```sh theme={null}
> conda repo service-accounts --channel <PRIMARY_CHANNEL> --user-id <SA_UID> --name <TOKEN_NAME> --permission <LEVEL> --create-token
> ```
>
> Comments
>
> Replace \<PRIMARY\_CHANNEL> with the channel you are creating a service account token for.\\
>
> Replace \<SA\_UID> with the service account user ID.\\
>
> Replace \<TOKEN\_NAME> with a name for your token.\\
>
> Replace \<LEVEL> with the permission level (`read`, `write`, or `manage`).

> [accordion] Create a token with a custom lifespan
>
> ```sh theme={null}
> conda repo service-accounts --channel <PRIMARY_CHANNEL> --user-id <SA_UID> --name <TOKEN_NAME> --permission <LEVEL> --max-days <DAYS> --create-token
> ```
>
> Comments
>
> Replace \<PRIMARY\_CHANNEL> with the channel you are creating a service account token for.\\
>
> Replace \<SA\_UID> with the service account user ID.\\
>
> Replace \<TOKEN\_NAME> with a name for your token.\\
>
> Replace \<LEVEL> with the permission level (`read`, `write`, or `manage`).\\
>
> Replace \<DAYS> with the number of days for the token to remain valid (omit this flag to prevent expiration).

> [accordion] Create a token with permissions across multiple channels
>
> ```sh theme={null}
> conda repo service-accounts --channel <PRIMARY_CHANNEL> --user-id <SA_UID> --name <TOKEN_NAME> --token-channels <TARGET_CHANNEL>,<TARGET_CHANNEL> --permission <LEVEL> --create-token
> ```
>
> Comments
>
> Replace \<PRIMARY\_CHANNEL> with the channel you are creating a service account token for.\\
>
> Replace \<SA\_UID> with the service account user ID.\\
>
> Replace \<TOKEN\_NAME> with a name for your token.\\
>
> Replace \<TARGET\_CHANNEL> with each channel you want to provide permissions for (comma-separated).\\
>
> Replace \<LEVEL> with the permission level (`read`, `write`, or `manage`).

### Listing all channel tokens

```sh theme={null}
conda repo service-accounts --channel <CHANNEL_NAME> --list-tokens
```

Comments

Replace \<CHANNEL\_NAME> with the channel you are listing service account tokens for.

### Listing tokens for a specific service account

To list all token IDs that a service account has to a specified channel:

```sh theme={null}
conda repo service-accounts --channel <CHANNEL_NAME> --list-tokens --user-id <SA_UID>
```

Comments

Replace \<CHANNEL\_NAME> with the channel you are listing service account tokens for.\\

Replace \<SA\_UID> with the service account user ID.

### Editing a token

To change a token's permission level:

```sh theme={null}
conda repo service-accounts --token-id <TOKEN_ID> --name <TOKEN_NAME> --permission <LEVEL> --edit-token
```

Comments

Replace \<TOKEN\_ID> with the token you want to edit.\\

Replace \<TOKEN\_NAME> with the name of the token.\\

Replace \<LEVEL> with the new permission level (`read`, `write`, or `manage`).

### Deleting a token

```sh theme={null}
conda repo service-accounts --token-id <TOKEN_ID> --delete-token
```

Comments

Replace \<TOKEN\_ID> with the token you want to delete.

## Related

* [Channel service accounts](https://anaconda.com/docs/psm-on-prem/6.8.0/admin/advanced/channel_service_account.md): Managing service accounts through the GUI
* [Authorization tokens](https://anaconda.com/docs/psm-on-prem/6.8.0/user/auth_token.md): Managing tokens through the GUI
* [`service-accounts` command reference](https://anaconda.com/docs/psm-on-prem/6.8.0/cli/commands/service-accounts): Full options and flags
