双因素认证(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 需要以下条件之一:
欲了解更多信息,请参阅 npm 关于发布包时要求两步验证的文档。
🌐 For more information, see the npm documentation on requiring 2FA for package publishing.
🌐 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.
| Action | CLI command |
|---|---|
| Log in to npm | npm login |
| Change profile settings (including your password) | npm profile set |
| Change 2FA modes for your user account | npm profile enable-2fa auth-and-writes |
| Disable 2FA for your user account | npm profile disable-2fa |
| Create tokens | npm token create |
| Revoke tokens | npm token revoke |
| Publish packages | npm publish |
| Unpublish packages | npm unpublish |
| Deprecate packages | npm deprecate |
| Change package visibility | npm access public/restricted |
| Change user and team package access | npm access grant/revoke |
| Change package 2FA requirements | npm 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.
| Action | CLI command |
|---|---|
| Log in to npm | npm login |
| Change profile settings (including your password) | npm profile set |
| Change 2FA modes for your user account | npm profile enable-2fa auth-only |
| Disable 2FA for your user account | npm profile disable-2fa |
| Create tokens | npm token create |
| Revoke tokens | npm token revoke |