Skip to main content

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

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:

Error: Command requires authentication: run `tuna login` or pass an API key. Find more information at: https://tuna.am/docs/guides/api
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. 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;
  • 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.

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:

    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 that can run tunnels in the TUNA_API_KEY variable. To save the key on the machine:

    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.

To check which account the CLI uses, run tuna whoami. All the ways to sign in are described in Sessions and API keys.