According to oficial documentation https://docs.npmjs.com/cli/v7/commands/npm-publish you could use the access param as follows
npm publish --access=restricted
If you do not want your scoped package to be publicly viewable (and installable) set --access=restricted.
Unscoped packages can not be set to restricted meaning you have to add the @scope prefix to your package i.e.: @foo/yeoman-generator-wherever.
If you want to publish the package to make it publicly accesible you can set the flag --access=public.
npm publish --access=public
My advise is to check the npm version and the documentation as maybe the default behaviour for npm publish differs so better to be explicit and set the flag of what you need.