Authenticate to use the CLI

Once you have installed the Snyk CLI using your chosen tool or operating system (OS), you need to authenticate with your Snyk account.

Supported authentication methods

Snyk supports the following authentication methods:

  • OAuth 2.0

  • Personal Access Token (PAT)

  • Snyk API token

Prerequisites

If your Snyk account is hosted on a SNYK-US-02, SNYK-EU-01, or SNYK-AU-01 endpoint rather than the default SNYK-US-01 endpoint, you need to configure the CLI environment before you authenticate with your Snyk account.

To do this, run the environment config command:

Environment config command
snyk config environment <ENVIRONMENT_NAME>

This example specifies the SNYK-EU-01 environment:

Example command with specified environment
snyk config environment SNYK-EU-01

Once the environment has been configured, authenticate using your preferred method.

Authenticate locally

This applies to: Homebrew, npm, Yarn, Scoop (Windows), and Direct binary downloads (standalone executables).

OAuth 2.0 (browser based)
  • Run the following command:

  • A browser window will open on a Snyk address. Click Authenticate.

  • Return to your terminal. You should see the message Your account has been authenticated.

For local service account testing, use the command:

Personal Access Token (PAT)

To authenticate in the terminal and save the profile locally, run the command:

Snyk API token

Run the command:

Configuration command

Add your PAT or API token to the Snyk CLI configuration using the snyk config command:

Environment variables

You can export local tokens to your local shell profile using the command:

Or run them for each command using:

Authenticate in Docker

Pass your chosen token into the container using Docker's environment flag during execution:

Authenticate in a CI/CD or GitHub action

This applies to: general CI/CD Pipelines (Jenkins, GitLab, CircleCI, and so on) and GitHub Actions.

Map your securely stored PAT or API token to the SNYK_TOKEN environment variable, or map your OAuth token to SNYK_OAUTH_TOKEN, directly within your pipeline configuration or GitHub Actions env block.

Last updated

Was this helpful?