---
title: "Log in to an instance with the Sitecore CLI"
slug: "log-in-to-an-instance-with-the-sitecore-cli"
abstract: "How to log in to a SitecoreAI instance using the Sitecore Command Line Interface (CLI)."
---
# Log in to an instance with the Sitecore CLI

For advanced use of the [Sitecore Command Line Interface (CLI)](https://doc.sitecore.com/sai/en/developers/sitecoreai/sitecore-command-line-interface.html "Sitecore Command Line Interface") against a SitecoreAI instance, such as using specific authorities and audiences, you can use the `sitecore cloud login` command.

> [!important]
> For regular operations against a SitecoreAI instance, you can use the [commands provided by the Sitecore CLI XM Cloud plugin](https://doc.sitecore.com/sai/en/developers/sitecoreai/sitecore-command-line-interface/plugins/xm-cloud-plugin.html "XM Cloud plugin").

> [!note]
> **XM Cloud is now SitecoreAI**
> Some code examples, images, and UI labels may still use XM Cloud while engineering assets are being updated.

For logging in to an instance using `sitecore cloud login`, the CLI allows two flows of authentication and authorization:

- An interactive user login, using a device code flow.
- A non-interactive client login, using a client credentials flow. This is used by clients such as Continuous Integration servers.

> [!note]
> Run the `dotnet sitecore cloud login --help` command for details on the `cloud login` command.

## Use an interactive user login (device code flow)

To log in with an interactive user login to an SitecoreAI instance, you must use the following:

- The authority URL. The default authority URL is `https://auth.sitecorecloud.io`.
- The audience URL: `https://api.sitecorecloud.io`.
- The predefined client ID: `Chi8EwfFnEejksk3Sed9hlalGiM9B2v7`.
- The URL of the SitecoreAI instance.
- Your username.
- Your password.

To log in:

1. In the console, go to your project folder.
2. Log in with the following command:

    ```
    dotnet sitecore cloud login --authority https://<AUTHORITY_URL> --cm https://<SITECOREAI_INSTANCE> --audience https://<SITECOREAI_AUDIENCE_URL> --client-id <CLIENT_ID> --allow-write true
    ```

    The `sitecore cloud login` command opens a login page in your browser.

3. On the login page, enter your username and password and click **OK**.

    The `sitecore cloud login` command stores your login arguments in the `.sitecore/user.json` file together with an access token. You are now logged in, and you can close the login webpage.

    > [!important]
    > Do not commit the `.sitecore/user.json` file to source control because it contains privileged information.

> [!tip]
> After logging in with the device flow, if you want to switch to the client credentials (non-interactive) flow, run the following command:
>
> dotnet sitecore cloud login --client-id <CLIENT_ID> --client-secret <CLIENT_SECRET> --client-credentials true
>
> When switching to the non-interactive login flow, use the [credentials generated when creating an authentication/automation client for your environment or organization](https://doc.sitecore.com/sai/en/developers/sitecoreai/deploying-sitecoreai/deploy-app/managing-sitecoreai-client-credentials.html "Managing SitecoreAI client credentials").

## Use a non-interactive client login (client credentials flow)

To use a non-interactive login flow with a [SitecoreAI](https://doc.sitecore.com/sai/en/users/sitecoreai/sitecoreai.html) instance, you need the following:

- [An authentication/automation client for your organization or environment](https://doc.sitecore.com/sai/en/developers/sitecoreai/deploying-sitecoreai/deploy-app/managing-sitecoreai-client-credentials.html "Managing SitecoreAI client credentials"). This provides a client ID and a client secret.
- The authority URL. The default authority URL is `https://auth.sitecorecloud.io`.
- The audience URL `https://api.sitecorecloud.io`.
- The URL of the [SitecoreAI](https://doc.sitecore.com/sai/en/users/sitecoreai/sitecoreai.html) instance.

To log in:

1. In the console, go to your project folder.
2. Log in with the following command:

    ```
    dotnet sitecore cloud login --authority https://<AUTHORITY_URL> --cm http://<SITECOREAI_INSTANCE> --audience https://<SITECOREAI_AUDIENCE_URL> --allow-write true --client-credentials true --client-id <CLIENT_ID> --client-secret <CLIENT_SECRET>
    ```

> [!tip]
> After logging in with the client credentials flow, if you want to switch to the device flow, run the following command:
>
> dotnet sitecore cloud login  --client-credentials false --client-id <CLIENT_ID>
>
> When switching to the interactive login flow, use the predefined client ID `Chi8EwfFnEejksk3Sed9hlalGiM9B2v7`.
