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

# Connect to Pulsar cluster using pulsarctl CLI tool

[`pulsarctl`](https://github.com/streamnative/pulsarctl) is a CLI tool that you can use to manage Pulsar clusters. This document provides examples of how to use the `pulsarctl` CLI tool to connect to a Pulsar cluster through a token or an OAuth2 credential file.

## Connect to a Pulsar cluster using a token

This example shows how to use the `pulsarctl` CLI tool to connect to your Pulsar cluster using a token and then list tenants available for this cluster.

```bash theme={null}
pulsarctl \
  --admin-service-url "WEB_SERVICE_URL" \
  --token "AUTH_PARAMS" \
  tenants list
```

Set the `admin-service-url` and `token` parameters based on the descriptions in the [prepare to connect to a Pulsar cluster](/private-cloud/v1/build/connect-prepare) user guide.

## Connect to a Pulsar cluster using an OAuth2 credential file

<Note title="Note">
  If it is the first time you install and use the `pulsarctl` CLI tool, you must use the [`pulsarctl context set`](https://doc-references.streamnative.io/pulsarctl/latest/index.html#-em-set-em--54) command to set a context (cluster) in advance.
</Note>

To connect to your Pulsar cluster using an OAuth2 credential file, follow these steps.

1. Generate the App credentials by following similar instructions in the [configure OAuth2 authentication](/private-cloud/v1/operating-streamnative-platform/security/oauth2-auth) user guide.

2. Save the App credentials into an OAuth2 credential file.

3. Create a context.

   The `pulsarctl` CLI tool uses a configuration file for cluster-specific settings. Each cluster is associated with a context. This example creates a context called `neo-1` based on the App registration details.

   ```bash theme={null}
   pulsarctl context set "neo-1" \
    --admin-service-url "${adminServiceURL}" \
    --issuer-endpoint "${domain}" \
    --audience "urn:sn:pulsar:${orgName}:${instanceName}" \
    --key-file "file://YOUR-KEY-FILE-PATH"
   ```

   * `admin-service-url`: the service URL of your Pulsar cluster.
   * `issuer-endpoint`: the URL of your OAuth2 identity provider.
   * `audience`: the audience of your Pulsar cluster.
   * `key-file`: the absolute path to your OAuth2 credential file.

4. Log in to your Pulsar cluster.

   ```bash theme={null}
   pulsarctl oauth2 activate
   ```

5. Get Pulsar resources.

   This example lists tenants for the cluster `neo-1`.

   **Input**

   ```bash theme={null}
   pulsarctl tenants list --cluster-name <neo-1>
   ```

   **OutPut**

   ```bash theme={null}
   +-------------+
   | TENANT NAME |
   +-------------+
   | public      |
   | pulsar      |
   | sn          |
   +-------------+
   ```
