使用安全密钥流从命令行登录

Sign in from the command line using security-key flow

  1. 在命令行上,键入 npm login 命令。

    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 https://registry.npmjs.org/
    Username: mona
    Password:
    Email: (this IS public) mona@github.com
    npm notice Open https://www.npmjs.com/login/913c3ab1-89a0-44bd-be8d-d946e2e906f0 to use your security key for authentication or enter OTP from your authenticator app
  3. 如果你已配置安全密钥,请打开命令行中显示的提供的 URL。或者,如果你已配置移动验证器,请跳至步骤 6。

    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. 在 CLI 提示符中输入一次性密码。

    Enter the one-time password into the CLI prompt.

    Enter one-time password:

使用 --auth-type=web 从命令行登录

Sign in from the command line using --auth-type=web

npm 8.14.0 及更高版本支持通过浏览器登录流程。这将成为 npm 9 中 npm 公共注册表的默认行为。

npm 8.14.0 and higher support login flow through the browsers. This will become the default behavior for the npm public registry in npm 9.

使用现有的浏览器会话

With an existing browser session

  1. 在命令行上,键入 npm login --auth-type=web 命令。

    On the command line, type the npm login --auth-type=web command.

  2. 当提示点击 "ENTER" 打开浏览器以启动登录流程或单击显示在命令行中提供的 URL 时。

    When prompted hit "ENTER" to open your browser to start the login flow or click the provided URL show in the command line.

    user@host:~$ npm login
    npm notice Log in on https://registry.npmjs.org/
    Authenticate your account at:
    https://www.npmjs.com/login?next=/login/cli/b1a2f96a-ce09-4463-954c-c99f6773b922
    Press ENTER to open in the browser...
  3. 单击使用安全密钥并按照浏览器特定的步骤进行身份验证。

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

    Screenshot showing security key prompt

    注意:如果你已配置为使用 TOTP,你将看到 TOTP 提示

    Note: If you have configured to use TOTP, you will see an TOTP prompt instead

没有现有的浏览器会话

Without an existing browser session

  1. 在命令行上,键入 npm login --auth-type=web 命令。

    On the command line, type the npm login --auth-type=web command.

  2. 当提示点击 "ENTER" 打开浏览器以启动登录流程或单击显示在命令行中提供的 URL 时。

    When prompted hit "ENTER" to open your browser to start the login flow or click the provided URL show in the command line.

    user@host:~$ npm login
    npm notice Log in on https://registry.npmjs.org/
    Authenticate your account at:
    https://www.npmjs.com/login?next=/login/cli/b1a2f96a-ce09-4463-954c-c99f6773b922
    Press ENTER to open in the browser...
  3. 在 npm“登录”页面上,输入您的帐户详细信息并单击登录 Screenshot of npm login dialog
  4. 单击使用安全密钥并按照浏览器特定的步骤进行身份验证。

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

    Screenshot showing security key prompt

    注意:如果你已配置为使用 TOTP,你将看到 TOTP 提示

    Note: If you have configured to use TOTP, you will see an TOTP prompt instead

npm 中文网 - 粤ICP备13048890号