掘金文章归档 · 第 52 篇 工程化 · 部署 系列 2/4 npm · 2FA

npm 发包的 2FA 验证

开启双因素认证后,登录与发布均需一次性动态密码

原文作者:随意_(掘金) | juejin.cn/post/7189504184381603898 | 发布于 2023-01-17 | 阅读 1,251 · 约 1 分钟

0背景

npm 对于已有的包更新和新的包发布,认为原先的 npm 登录密码安全性太差,增加了 2FA 校验。npm 给出的官方文档地址为:docs.npmjs.com/configuring…

1如何开启 2FA

  1. 登录到 npm 官网(地址 www.npmjs.com),输入账号密码;
  2. 手机应用商店下载 Authenticator App;
  3. npm 中选择 QE 登录,用下载的 Authenticator App 扫码关联,这样 Authenticator App 可关联到你的 npm 账户;
  4. npm 源切换到 npm 官方路径;
  5. npm login 输入账号密码;
  6. npm notice "Please use the one-time password (OTP) from your authenticator application" 提示时输入一次性校验密码;
  7. npm publish 发布时候需要增加上动态密码:npm publish --opt=六位动态密码
⚠️ 提示:开启 2FA 校验后,发布和更新均需要一次性密码。当然,你也可以在 account 中关闭掉一次性密码登录。