> ## 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.

# Getting started with the CLI

The `conda-repo-cli` package is the command-line interface (CLI) tool for interacting with Package Security Manager. You can use it to perform most of the actions available through the graphical user interface, including managing channels, mirrors, policies, packages, and service accounts.

> [!NOTE]
>
> The actions you can perform in the CLI are determined by your group/role [permission levels](https://anaconda.com/docs/psm-on-prem/6.8.0/admin/user_config/permissions.md#permission-levels). If you are unsure of your permissions or need additional permissions, contact your Package Security Manager administrator.

## Installing the CLI

`conda-repo-cli` is included with Anaconda Distribution. If you installed Miniconda, you'll need to install the package:

1. Open Anaconda Prompt (Terminal on macOS/Linux) and run:

   ```sh theme={null}
   conda install --name base conda-repo-cli
   ```

   > [!NOTE]
   >
   > As an administrator, you can mirror or upload this package into a public channel within your Package Security Manager instance, allowing your users to install it by running:
   >
   > ```sh theme={null}
   > conda install --name base --channel https://<FQDN>/api/repo/<CHANNEL> conda-repo-cli
   > ```
   >
   > Comments
   >
   > Replace \<FQDN> with your PSM fully qualified domain name.\\
   >
   > Replace \<CHANNEL> with the name of the channel you've hosted `conda-repo-cli` in.

2. Verify your installation:

   ```sh theme={null}
   conda repo --version
   ```

## Configuring the CLI

You must configure a repository site before you can log in. Configuring the site tells `conda-repo-cli` which Package Security Manager URL to connect to. This information is recorded in your `.conda/repo-cli-config.yaml` file.

**1. Set your Package Security Manager site**

> [tab] Default site name
>
> To add your Package Security Manager URL and set it as the default site, run:
>
> ```sh Command theme={null}
> conda repo config --set-site <DOMAIN_NAME>
> ```
>
> ```sh Example theme={null}
> conda repo config --set-site psm.example.com
> ```
>
> Comments
>
> Replace \<DOMAIN\_NAME> with your Package Security Manager domain name.

> [tab] Custom site name
>
> To name your site yourself, set the site URL and the default site separately:
>
> ```sh Command theme={null}
> conda repo config --set sites.<SITE_NAME>.url <URL>/api
> conda repo config --set default_site <SITE_NAME>
> ```
>
> ```sh Example theme={null}
> conda repo config --set sites.psm-server.url https://psm.example.com/api
> conda repo config --set default_site psm-server
> ```
>
> Comments
>
> Replace \<SITE\_NAME> with a short name to reference your Package Security Manager.\\
>
> Replace \<URL> with your Package Security Manager URL, including `https://`.

**2. Enable OAuth or SAML Optional**

If your Package Security Manager uses OAuth or SAML for authentication, run the following command to enable the standard authorization flow:

```sh theme={null}
conda repo config --set oauth2 true
```

**3. Confirm your configuration**

To view your configuration, run:

```sh theme={null}
conda repo config --show-sources
```

The output shows the path to your `.conda/repo-cli-config.yaml` file and its contents. Confirm that the `url` for your default site matches your Package Security Manager URL.

## Logging in

To log in, run the following command:

```sh theme={null}
conda repo login
```

When prompted, enter your Package Security Manager username and password. For example:

```text theme={null}
(base) ➜  ~ conda repo login
Username: anaconda
Password:
login as ADMIN successful
```

> [!NOTE]
>
> If you are using OAuth or SAML, running `conda repo login` opens a browser window where you log in with your organization's SSO credentials. After you log in, the window displays **Token Received**. Close the browser window and return to your terminal.

To confirm that you're logged in, run:

```sh theme={null}
conda repo whoami
```

## Configuring conda to use Package Security Manager

The `.condarc` configuration wizard points conda at your Package Security Manager, so `conda install` and other conda commands use your Package Security Manager channels. It adds channels from your organization to your `.condarc` file and sets the `channel_alias` for your deployment. You must be logged in to run the wizard.

**1. Run the wizard**

```sh theme={null}
conda repo wizard
```

The wizard shows channels from your Package Security Manager organization and guides you through adding them to your `.condarc`. You *must* set at least one default channel for the wizard to continue.

> [!WARNING]
>
> Misspelled channel names are not accepted. If you enter a channel name that does not match an existing channel, a warning appears and no channel is added.
>
> ***
>
> Only add channels that contain packages. If any default channel is empty, every conda command fails with `UnavailableInvalidChannel: HTTP 404 Not Found`.

Your output looks something like this:

```text Example command workflow expandable theme={null}
Conda configuration wizard.
This wizard will configure your CondaRC file using channels from https://<FQDN>

The CondaRC path is /Users/<USER>/.condarc

The following channels are available:
Name                           | Mirror | Privacy         | Owners
---------------------------------------------------------------------------
data-science                   |  ︎ ✔    | private         | admin
web-devs                       |  ︎      | private         | admin

Provide a space-separated list of channels to set as default_channels
It is common to add mirror channels here.
: data-science web-devs

If you wish to add channels to the "channels" list
provide a space-separated list. You may leave this blank.
:
The following Conda configuration will be applied
channel_alias: https://<FQDN>/api/repo
default_channels:
  - data-science
  - web-devs
channels:
  - defaults
channel_settings:
  - channel: https://<FQDN>/*
    auth: anaconda-auth
Confirm changes to /Users/<USER>/.condarc
(The current condarc file will be archived) [Y, n]: y
Backing up your current condarc file to /Users/<USER>/.condarc.backup
```

> [!NOTE]
>
> The wizard adds each default channel to the top of the `default_channels` list, so the list in your `.condarc` ends up in the reverse of the order you entered. Conda searches channels from the top of the list down, so enter your highest-priority channel last. To check the final order, run:
>
> ```sh theme={null}
> conda config --show default_channels
> ```

**2. Remove the wizard's channel settings**

> [!WARNING]
>
> This is a known issue in `conda-repo-cli`. The wizard adds a `channel_settings` block to your `.condarc` that prevents conda from authenticating to Package Security Manager. Until you remove it, conda commands fail with `AnacondaAuthError: Received authentication error (401)`.

Open your `.condarc` file and delete the following lines:

```yaml theme={null}
channel_settings:
- auth: anaconda-auth
  channel: https://<FQDN>/*
```

Leave the rest of your `.condarc` unchanged. Conda uses the token that `conda repo login` saved, so you don't need to install a separate token.

**3. Confirm conda can reach your channels**

Search for a package in one of your default channels:

```sh theme={null}
conda search <PACKAGE_NAME>
```

Comments

Replace \<PACKAGE\_NAME> with the name of a package in one of your default channels.

The results list your Package Security Manager channels in the **Channel** column.

> [!TIP]
>
> If the wizard creates problems with your `.condarc`, revert the changes:
>
> ```sh theme={null}
> conda repo wizard --restore
> ```

For a complete list of commands and options, see the [command reference](https://anaconda.com/docs/psm-on-prem/6.8.0/cli/commands/index).
