Running npm commands related to accessing GitHub registry when 2FA is set

Is it possible to use the --otp parameter to npm commands such as npm login to authenticate for GitHub Packages related actions? npm seems to provide for but I’m getting the following error even with --otp set:

> npm login --registry= --otp 123456
Username: sangeeth96
Email: (this IS public)

npm ERR! code E401
npm ERR! 401 Unauthorized - PUT - Error authenticating user: Must specify two-factor authentication OTP code.

Side note: please create a section for GitHub Packages related questions.

Hi @sangeeth96 ,

It should be not supported. There is no 2FA setting for package setting in github package registry ‘’, which is different with ‘’. Typically personal access token is used to authenticate to github package registry, please refer to official doc for more details.

If you would like to add this feature, according to the policy, please share your idea here where github product manager will take a review.


@sangeeth96 were you able to cope this?

You can set up github packages config even after 2FA is enabled, just don’t use your real password to login, but instead a new token.

  1. get token
    generate a token in with permissions of repo, write:packages, read:packages
  2. login with the above token as password when prompted, instead of the github login password
    npm login --registry=