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

# Login

> Authenticate to the env zero remote backend from your local machine using a personal API key token for local terraform login and remote plan.

# Local Login to env zero Remote Backend

Remote backends allow running your Terraform deployments both on env zero and locally with access to the remote state. To use the Remote Backend locally, you must log in for your requests will be authorized.\
To login, ensure the following conditions are met:

1. You have a login [Token](/guides/admin-guide/remote-backend/login/#generating-a-token)
2. The current path is the directory of the Terraform stack
3. The Terraform stack defines a properly configured env zero backend

```hcl backend.tf theme={null}
terraform {
  cloud {
    hostname     = "backend.api.env0.com"
    organization = "<org-id>.<project-id>"
    workspaces {
      name = "my-first-remote-apply"
    }
  }
}
```

<Info>
  **A note regarding the PROJECT\_ID in the backend configuration**

  The PROJECT\_ID is only required if the env zero environment does not exist in the env zero UI. For example, if this is the first time you are creating a new env zero environment with the env zero remote backend configuration, you need to specify the PROJECT\_ID so that env zero will know where to put your new env zero environment. Otherwise, if you are updating the backend configuration for an existing env zero environment, you do not need to specify the PROJECT\_ID.
</Info>

To log in:

1. Run `terraform login backend.api.env0.com`
2. Enter `yes` when prompted
3. Insert your `token`

<Info>
  **A note regarding Module Registry & Remote Backend**

  Technically, the two services are hosted on different api endpoints, so to use both the module registry and the remote backend with the same API key, you will have to also set up the token for `api.env0.com`. Please see the section on [Private Registry authorization](/guides/admin-guide/private-registry/#authorization) for more details.
</Info>

# Generating a Token

To generate a token, you must create a [Personal API Key](/guides/admin-guide/user-role-and-team-management/api-keys/#personal-api-key).\
After the API Key has been created, the token will be listed under the `Using it locally for Remote Backend`.\
Alternatively, Admins can create an [API Key with a specific role](/guides/admin-guide/user-role-and-team-management/api-keys/#how-to-create-an-api-key).

<Warning>
  Avoid Creating One Token For Multiple Users

  Terraform's workspace locking mechanism prevents state corruption by enforcing that two users cannot plan nor apply simultaneously and overwrite each other's state.

  Issuing the same token to multiple users causes the locking mechanism to be ignored, as env zero will be unable to differentiate between different users when they use the same token.
</Warning>

# Logout

In case you need to logout, you can browse to `backend.api.env0.com/logout/{Token}`

## Next steps

* [Running Remote Plan](/guides/admin-guide/remote-backend/remote-plan) - Run Terraform plans remotely via env zero after logging in.
* [Running Remote Apply](/guides/admin-guide/remote-backend/remote-apply) - Apply Terraform changes remotely through env zero.
* [User API Keys](/guides/admin-guide/user-role-and-team-management/api-keys) - Generate and manage the API keys used for authentication.
