---
title: "Authentication"
description: "Documentation for the vlt client and the vlt registry."
url: "https://docs.vlt.io/client/auth"
image: "https://docs.vlt.io/og/client/auth"
lang: "en"
---

# Authentication

The vlt client supports logging into multiple different registries. When more than one is configured, scope an auth command to a specific one with [`vlt registry <alias> <command>`](https://docs.vlt.io/client/commands/registry.md) (for example `vlt registry main whoami`). See [Targeting a specific registry](https://docs.vlt.io/client/registries.md#targeting-a-specific-registry).

Installing public packages needs no login: with no config, vlt uses its public, read-only npm mirror. If you're setting up a vlt.io account for the first time, start with [`vlt setup`](https://docs.vlt.io/client/registries.md#getting-started-with-vlt-setup) — it authenticates and configures your account's registry aliases in one step. The commands below cover logging into individual registries directly.

## npm Web Login

To log into a registry that supports the npm web login, such as the public npm registry, use the `vlt login` command.

For example, to log into the default registry:

```bash title="Terminal"
$ vlt login
```

To log into a custom registry that supports npm web login, run the same command, specifying the registry to log into:

```bash title="Terminal"
$ vlt login --registry=https://my-custom-registry.mycompany.local/
```

To remove your authorization to a given registry, including attempting to destroy the token on the server side, use the `vlt logout` command.

## Other Registries

If your registry provides a bearer token that should be presented for authentication, it can be added using the `vlt token add` command.

This will prompt you to paste in the token.

To remove a token from vlt's keychain, use the `vlt token rm` command. Note that this will _not_ delete the token from the server; it only removes it from the local keychain store.

A token follows redirects that stay on the same origin (scheme, host and port), even to paths outside the registry URL, and is dropped when a redirect changes origin.

## CI (and Other Headless Environments)

A token for the default registry can be provided in the `VLT_TOKEN` environment variable. The default registry is the `registry` option (or `VLT_REGISTRY`) if set, else the `registries` alias named by `default-registry-alias` (`npm` by default: vlt's public npm mirror unless you configure `registries.npm`, e.g. with `vlt setup`).

For example:

```
VLT_TOKEN="helloworldtokendeadbeef" vlt install
```

To provide a token for other registries, set a `VLT_TOKEN_{...}` variable named after the registry URL: drop the trailing `/` and replace each run of non-alphanumeric characters with `_`. The path is part of the name, e.g. `https://registry.vlt.io/acme/main/` becomes `VLT_TOKEN_https_registry_vlt_io_acme_main`.

```
VLT_TOKEN_https_my_custom_registry_mycompany_local="helloworldtokendeadbeef" vlt install
```

These variables apply to configured registries (`registry`, `registries`, `scoped-registries` and `jsr-registries`, built-in `gh` and `jsr` included) and to registries you've logged in to. The token is only sent to URLs under that registry URL (plus same-origin redirects, see above).

For the same registry, `VLT_TOKEN` beats `VLT_TOKEN_{...}`, and both beat keychain tokens.

## Trusted publishing

With [trusted publishing](https://docs.npmjs.com/trusted-publishers), vlt can publish from CI without static tokens. vlt detects the CI environment, requests an OIDC ID token from the provider, and exchanges it with the registry for a short-lived publish token. Everything happens behind the scenes.

The registry must support trusted publishing. The vlt.io registry supports it from GitHub Actions; see [Trusted publishing](https://docs.vlt.io/registry/publishing/trusted-publishing.md) to set it up.

### Supported Providers

- **GitHub Actions** — native support, no extra config
- **GitLab CI** — via `NPM_ID_TOKEN` environment variable
- **CircleCI** — via `NPM_ID_TOKEN` environment variable

### GitHub Actions

Add `id-token: write` to the job's permissions and vlt handles the rest:

```yaml title="github-actions.yml"
jobs:
publish:
  runs-on: ubuntu-latest
  permissions:
    contents: read
    id-token: write
  steps:
    - uses: actions/checkout@v4
    - uses: vltpkg/setup-vlt@v1
    - run: vlt publish
```

### GitLab CI / CircleCI

Set the `NPM_ID_TOKEN` environment variable with the OIDC ID token provided by your CI platform. vlt reads it automatically and exchanges it for a publish token.

### How It Works

When you run `vlt publish`, vlt checks for an available OIDC ID token from the CI environment. It sends that token to the registry's token endpoint, which verifies the token and returns a short-lived credential. vlt uses that credential for the publish request. No tokens are stored, and nothing persists after the job finishes.

### Fallback Behavior

If trusted publishing isn't available — for example, the registry doesn't support it, or the required permissions aren't configured — vlt silently falls back to `VLT_TOKEN` or keychain-based auth. No errors, no interruptions.

## OTP

One-time password (OTP) and MFA is supported for non-headless environments by opening a web browser or prompting on the command line for a OTP from your authenticator app, when the registry prompts for multifactor auth.

For headless environments, an OTP token may be provided in the `VLT_OTP` environment variable.

## Why Environment Variables and Not Config

The vlt client is designed to make it less likely that passwords are leaked in configuration files that might be checked into source control, which is a surprisingly common security failure mode.

With vlt, sensitive information is _only_ kept in a tightly restricted keychain file, or in the environment. Of course, perfect security is often impossible, but it is nevertheless important to do our best to make it less likely that passwords can be leaked by accident.

## Credential Management

Each "identity" in vlt is a set of authentication tokens for known registries.

For example, you could have a `corp` identity with the credentials that you use for the work on corporate projects, and a `personal` account with your own personal npm registry login credentials.

Running `vlt config set identity=corp` will switch into `corp` mode. `vlt config set identity=personal` will switch into `personal` mode.

This can also be set in a project root with a `vlt.json` config file, to make it easier to set per project. For example, you could have this in your `vlt.json` in the project root:

```json
{
  "identity": "corp"
}
```
