# cs login (/docs/cli/login)

`cs login` opens your browser to CoreSpeed's sign-in, completes OAuth 2.1 with
PKCE against a loopback callback on `127.0.0.1`, and stores the tokens under
`~/.config/cs`. The result is a **member session** — the same principal as
browser sign-in from an agent — so everything a signed-in member may do,
including minting keys, which no API key may, is available to the CLI. See
[Authentication](/docs/authentication#what-a-credential-may-do).

## Usage \[#usage]

```bash
cs login                 # opens the browser; prints the URL to visit if it cannot
cs login --org org_01J…  # sign in to one organization
```

## Choosing an organization \[#choosing-an-organization]

A member of several organizations picks one in the terminal. The default is
the organization the browser sign-in selected, then the one this machine used
last:

```text title="Output"
Choose an organization:
  1) org_01J… (Acme) [admin]  (default)
  2) org_01K… (Side project) [member]
Organization [1]: 2
Logged in as ada@example.com.
Organization: org_01K… (Side project) [member]
```

`--org` skips the question and hands the organization to the sign-in page, which
applies that organization's sign-in rules (SSO, MFA) before it lets you in.
Without a terminal (CI, agents, pipes) there is no question: the default is
used, and the output says how many organizations you belong to. Change it later
with [`cs switch`](/docs/cli/switch).

## What happens \[#what-happens]

* The browser reuses its CoreSpeed sign-in when it has one, so no password is
  asked. `Logged in as …` names the account that was used; to use another,
  sign out on the dashboard first, then run `cs logout` and `cs login`.
* A first sign-in provisions your personal organization, and the output marks
  it `— created by this sign-in`.
* The access token lives five minutes. Every other command refreshes it
  silently, so you sign in once per machine, not once per command.
* Until you sign in, every command that needs the session fails with exit
  code `3` and ``Error: not logged in; run `cs login` ``.
* [`cs logout`](/docs/cli/logout) removes the stored session.

## Signing in on a remote machine \[#signing-in-on-a-remote-machine]

On a machine without a browser, such as a server you reach over SSH, open the
printed URL in your local browser. Sign-in finishes by redirecting that browser
to `127.0.0.1` on the machine running `cs`, so fix the port and forward it:

```bash
ssh -L 8765:127.0.0.1:8765 you@devbox
CS_LOGIN_PORT=8765 cs login
```

Sign-in waits five minutes for the browser. The session is stored in
`CS_CONFIG_DIR`, `~/.config/cs` by default.