> Markdown version of https://tuna.am/en/docs/troubleshooting/errors/not-logged-in/. Documentation index: [llms.txt](https://tuna.am/en/llms.txt), full text in one file: [llms-full.txt](https://tuna.am/en/llms-full.txt). Any page is available as Markdown: append `.md` to its URL without the trailing slash.

# Not logged in, run `tuna login` or pass --api-key

```text
FATA[12:00:00] Not logged in, run `tuna login` or pass --api-key

```

tuna CLI prints this error when you start a tunnel and exits right away. The `tuna domain`, `tuna endpoint`, `tuna api-key`, and `tuna monitor status` commands print a different message, and a tunnel running as a background service prints a third one:

```text
Error: Command requires authentication: run `tuna login` or pass an API key. Find more information at: https://tuna.am/docs/guides/api

```

```text
FATA[12:00:00] Background service requires an api key: pass --api-key or save it with `tuna login --with-api-key`

```

## Cause

The CLI found nothing to sign in with. It checks the `--api-key` flag, the `TUNA_TOKEN` and `TUNA_API_KEY` environment variables, the saved session, and the key in the [config file](https://tuna.am/en/docs/guides/config-file.md). If all of them are empty, the command exits with this error.

Common cases:

* nobody has run `tuna login` on this machine or as this user yet;
* the command runs as another user, for example via `sudo`: root has its own session and config file and can't see your user's session;
* the `TUNA_API_KEY` variable wasn't passed to CI or the container;
* the system keyring didn't respond or isn't available, so the CLI couldn't read the session. If the keyring didn't respond, a `Failed to read saved session` warning comes before the error — see [System keyring did not respond](https://tuna.am/en/docs/troubleshooting/errors/system-keyring-did-not-respond.md);
* the session expired or was terminated: the CLI deletes such a session and shows this error on the next run. See [session expired or revoked](https://tuna.am/en/docs/troubleshooting/errors/session-expired-or-revoked.md).

A background service runs without an interactive login and doesn't use the session, so it needs an API key.

## What to do

* On your own computer, log in:

  ```shell
  tuna login

  ```

* On a server you reached over SSH, log in with a link confirmed from another device: `tuna login --no-browser`.

* In CI, Docker, and scripts, pass an [API key](https://my.tuna.am/api_keys?lang=en) that can run tunnels in the `TUNA_API_KEY` variable. To save the key on the machine:

  ```shell
  echo "$TUNA_API_KEY" | tuna login --with-api-key

  ```

* Reinstall the service with `tuna service install` as the user who is logged in: the CLI issues a separate key for the service. See [Running in the background](https://tuna.am/en/docs/tunnels/guides/service.md#service-key).

To check which account the CLI uses, run `tuna whoami`. All the ways to sign in are described in [Sessions and API keys](https://tuna.am/en/docs/guides/sessions-and-api-keys.md).
