Skip to content

Accessing npm using two-factor authentication

Sign in from the command line using security-key flow

  1. On the command line, type the npm login command.

  2. When prompted, provide your username, password, and email address.

    user@host:~$ npm login
    npm notice Log in on
    Username: mona
    Email: (this IS public)
    npm notice Open to use your security key for authentication or enter OTP from your authenticator app
  3. If you have configured a security-key, open the provided URL shown in the command line. Alternatively, if you have configured a mobile authenticator skip to step 6.

  4. Click on Use security key and follow the browser specific steps to authenticate.

    Screenshot showing security key prompt
  5. Copy the generated token

    Screenshot showing a sample token generated while using WebAuthn for cli login
  6. Enter the one-time password into the CLI prompt.

    Enter one-time password: