目录

双因素认证(2FA) 通过以下方式确认你的身份,以防止未经授权访问你的账户:

  • 你知道的东西(例如,密码)。
  • 你拥有的东西(例如,身份证或加密密钥)。
  • 你的身份(例如指纹或其他生物特性数据)。

当你启用双重身份验证(2FA)时,在对你的账户或你有写权限的包执行某些操作之前,系统将提示你进行第二种身份验证。你将被要求使用 安全密钥 进行身份验证。

🌐 When you enable 2FA, you will be prompted for a second form of authentication before performing certain actions on your account or packages to which you have write access. You will be prompted to authenticate with a security-key.

注意: 双因素认证为你的账户提供了对抗攻击者的最佳安全保障。我们强烈建议你在注册后尽快在账户上启用双因素认证(2FA)。

重要: 发布到 npm 需要以下条件之一:

  • 你的账户已启用双重身份验证 (2FA),或者
  • 启用绕过双重身份验证 (2FA) 的细粒度访问令牌

欲了解更多信息,请参阅 npm 关于发布包时要求两步验证的文档。

🌐 For more information, see the npm documentation on requiring 2FA for package publishing.

npm 上的双重身份验证

🌐 Two-factor authentication on npm

可以为授权和写入启用 npm 上的双重身份验证,或者仅启用授权。

🌐 Two-factor authentication on npm can be enabled for authorization and writes, or authorization only.

授权和写入

🌐 Authorization and writes

默认情况下,双重身份验证(2FA)已启用用于授权和写入操作。对于某些授权操作以及写入操作,我们将要求提供第二种形式的身份验证。

🌐 By default, 2FA is enabled for authorization and writes. We will request a second form of authentication for certain authorized actions, as well as write actions.

ActionCLI command
Log in to npmnpm login
Change profile settings (including your password)npm profile set
Change 2FA modes for your user accountnpm profile enable-2fa auth-and-writes
Disable 2FA for your user accountnpm profile disable-2fa
Create tokensnpm token create
Revoke tokensnpm token revoke
Publish packagesnpm publish
Unpublish packagesnpm unpublish
Deprecate packagesnpm deprecate
Change package visibilitynpm access public/restricted
Change user and team package accessnpm access grant/revoke
Change package 2FA requirementsnpm access 2fa-required/2fa-not-required

仅授权

🌐 Authorization only

如果你仅为授权启用双重身份验证,我们只会在某些被授权的操作中请求第二种身份验证方式。

🌐 If you enable 2FA for authorization only. We will request a second form of authentication only for certain authorized actions.

ActionCLI command
Log in to npmnpm login
Change profile settings (including your password)npm profile set
Change 2FA modes for your user accountnpm profile enable-2fa auth-only
Disable 2FA for your user accountnpm profile disable-2fa
Create tokensnpm token create
Revoke tokensnpm token revoke

目录