1 ---
2 title: About two-factor authentication
3 redirect_from:
4 - /getting-started/using-two-factor-authentication
5 ---
6
7 [Two-factor authentication (2FA)][2fa] protects against unauthorized access to your account by confirming your identity using:
8
9 - Something you know (e.g., a password).
10 - Something you have (e.g., an ID badge or a cryptographic key).
11 - Something you are (e.g., a fingerprint or other biometric data).
12
13 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][webauthn].
14
15 - The security-key flow allows you to use biometric devices such as Apple [Touch ID][touch-id], [Face ID][face-id] or [Windows Hello][windows-hello] as well as physical keys such as [Yubikey][yubikey], [Thetis][thetis] or [Feitian][feitian] as your 2FA.
16
17 <Note>
18
19 **Note:** Two-factor authentication provides the best possible security for your account against attackers. We strongly recommend enabling 2FA on your account as soon as possible after you sign up.
20
21 </Note>
22
23 ## Two-factor authentication on npm
24
25 Two-factor authentication on npm can be enabled for authorization and writes, or authorization only.
26
27 ### Authorization and writes
28
29 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.
30
31 | Action | CLI command |
32 | :------------------------------------------------ | :----------------------------------------------------- |
33 | Log in to npm | [`npm login`][login] |
34 | Change profile settings (including your password) | [`npm profile set`][profile-set] |
35 | Change 2FA modes for your user account | [`npm profile enable-2fa auth-and-writes`][2fa-enable] |
36 | Disable 2FA for your user account | [`npm profile disable-2fa`][2fa-disable] |
37 | Create tokens | [`npm token create`][token-create] |
38 | Revoke tokens | [`npm token revoke`][token-revoke] |
39 | Publish packages | [`npm publish`][publish] |
40 | Unpublish packages | [`npm unpublish`][unpublish] |
41 | Deprecate packages | [`npm deprecate`][deprecate] |
42 | Change package visibility | [`npm access public/restricted`][access] |
43 | Change user and team package access | [`npm access grant/revoke`][access] |
44 | [Change package 2FA requirements][pkg-2fa] | [`npm access 2fa-required/2fa-not-required`][access] |
45
46 <Note>
47
48 **Note:** [Granular access tokens][granular-tokens] can be configured to bypass 2FA requirements, making them ideal for CI/CD workflows and automation scenarios. When a granular access token is set to bypass 2FA, operations performed with that token will not require additional authentication factors. **Since legacy automation tokens are being deprecated, granular access tokens with 2FA bypass are now the recommended replacement**, providing the same automation benefits with enhanced security features like expiration dates, scope restrictions, and IP limitations.
49
50 </Note>
51
52 ### Authorization only
53
54 If you enable 2FA for authorization only. We will request a second form of authentication only for certain authorized actions.
55
56 | Action | CLI command |
57 | :------------------------------------------------ | :----------------------------------------------- |
58 | Log in to npm | [`npm login`][login] |
59 | Change profile settings (including your password) | [`npm profile set`][profile-set] |
60 | Change 2FA modes for your user account | [`npm profile enable-2fa auth-only`][2fa-enable] |
61 | Disable 2FA for your user account | [`npm profile disable-2fa`][2fa-disable] |
62 | Create tokens | [`npm token create`][token-create] |
63 | Revoke tokens | [`npm token revoke`][token-revoke] |
64
65 [login]: https://docs.npmjs.com/cli/adduser
66 [profile-set]: https://docs.npmjs.com/cli/profile
67 [2fa-enable]: https://docs.npmjs.com/cli/profile
68 [2fa-disable]: https://docs.npmjs.com/cli/profile
69 [token-create]: https://docs.npmjs.com/cli/token
70 [token-revoke]: https://docs.npmjs.com/cli/token
71 [publish]: https://docs.npmjs.com/cli/publish
72 [unpublish]: https://docs.npmjs.com/cli/unpublish
73 [deprecate]: https://docs.npmjs.com/cli/deprecate
74 [access]: https://docs.npmjs.com/cli/access
75 [pkg-2fa]: /requiring-2fa-for-package-publishing-and-settings-modification
76 [granular-tokens]: /integrations/integrating-npm-with-external-services/about-access-tokens#about-granular-access-tokens
77 [webauthn]: https://webauthn.guide/
78 [can-i-use]: https://caniuse.com/#search=webauthn
79 [u2f]: https://en.wikipedia.org/wiki/Universal_2nd_Factor
80 [windows-hello]: https://support.microsoft.com/en-us/windows/learn-about-windows-hello-and-set-it-up-dae28983-8242-bb2a-d3d1-87c9d265a5f0
81 [touch-id]: https://support.apple.com/en-gb/HT204587
82 [face-id]: https://support.apple.com/en-us/HT208108
83 [yubikey]: https://www.yubico.com/
84 [thetis]: https://thetis.io/
85 [feitian]: https://www.ftsafe.com/
86 [totp]: https://en.wikipedia.org/wiki/Time-based_one-time_password
87 [2fa]: https://en.wikipedia.org/wiki/Multi-factor_authentication