Skip to content

sched/nsh: Remove Hard-coded Default Password#18715

Open
Abhishek-2808 wants to merge 3 commits intoapache:masterfrom
Abhishek-2808:Issue-16822
Open

sched/nsh: Remove Hard-coded Default Password#18715
Abhishek-2808 wants to merge 3 commits intoapache:masterfrom
Abhishek-2808:Issue-16822

Conversation

@Abhishek-2808
Copy link
Copy Markdown

Summary

This PR introduces build-time generation of the /etc/passwd file for the ROMFS image when authentication is enabled.

Instead of relying on a static etc/passwd file embedded in the source tree, the passwd entry is now generated during the build using the configuration values:

  • CONFIG_ETC_ROMFS_PASSWD_USER
  • CONFIG_ETC_ROMFS_PASSWD_PASSWORD
  • CONFIG_ETC_ROMFS_PASSWD_UID
  • CONFIG_ETC_ROMFS_PASSWD_GID
  • CONFIG_ETC_ROMFS_PASSWD_HOME

The generated passwd entry is written into the ROMFS staging directory and included in the firmware image.

Behavior

Authentication disabled

  • No passwd generation occurs.
  • System behavior remains unchanged.

Authentication enabled

  • The build generates /etc/passwd automatically.
  • The password is hashed before being stored in the ROMFS image.
  • The plaintext password is never embedded in the firmware.

Password missing

  • If CONFIG_ETC_ROMFS_GENPASSWD=y but the password is empty, the build fails with an explicit error.

This ensures that credentials are always explicitly configured when authentication is enabled and prevents firmware images from being built with empty passwords.

Security Improvement

Previously /etc/passwd could be included as a static file in the ROMFS source tree.
With this change, the credentials are generated at build time and must be explicitly configured, avoiding implicit or default credentials in firmware images.

Testing

General passwd entry
image

Plaintext passwd check
image

Build failure when passwd is empty
image

@Abhishek-2808
Copy link
Copy Markdown
Author

@acassis Please check this PR.

Note: This PR is a re-submission of a previously approved PR. The original PR became inaccessible because my GitHub account was mistakenly flagged and is under manual review. Recreating it here with the same changes for review and merge.

@github-actions github-actions bot added Area: Build system Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces. Board: risc-v Board: simulator labels Apr 12, 2026
acassis
acassis previously approved these changes Apr 12, 2026
@acassis
Copy link
Copy Markdown
Contributor

acassis commented Apr 12, 2026

@Abhishek-2808 some suggestions:

Improve the error message to help the user to find where to fix the password:
Run 'make menuconfig' and select a password at: Board Selection ---> Auto-generate /etc/passwd at build time ---> Admin password

This PR is a breaking change, so, please include "!" before the commit title and include a Breaking Changes in the commit message, read https://nuttx.apache.org/docs/latest/contributing/guide.html for more info about it.

Since NuttX is a POSIX and Unix-like system, I think it make more sense to use the "root" username instead of "admin". So change the saved username from "admin" to "root" (you can keep the Admin name in the menuconfig.

@linguini1 @cederom do you agree?

@cederom
Copy link
Copy Markdown
Contributor

cederom commented Apr 12, 2026

@acassisL Since NuttX is a POSIX and Unix-like system, I think it make more sense to use the "root" username instead of "admin". So change the saved username from "admin" to "root" (you can keep the Admin name in the menuconfig.

Thanks Alan, yes we may switch to root and this was my first search too when looking at NuttX. We may ask about this on dev@ too :-)

Thanks for requesting breaking change mark! :-)

update: I have just asked on dev@ :-)

Introduce mkpasswd, a pure-C host tool for generating encrypted password
files at build time using TEA encryption. This enables secure,
credential-free firmware images while allowing build-time password
configuration.

Changes:
* Add mkpasswd.c host tool for TEA-based password hashing and encryption
* Integrate mkpasswd into Make build system (tools/Makefile.host)
* Add CMake support for mkpasswd compilation and ROMFS passwd generation
* Add CONFIG_BOARD_ETC_ROMFS_PASSWD_* configuration options to Kconfig
* Implement credential exclusion from defconfig to prevent password leaking
* Update savedefconfig.cmake to strip sensitive credentials
* Fix mkdir() portability for Windows Native builds (CONFIG_WINDOWS_NATIVE)
* Change default username from "admin" to "root" (POSIX convention)
* Improve build-failure error message with full menuconfig navigation path

BREAKING CHANGE: Boards enabling CONFIG_BOARD_ETC_ROMFS_PASSWD_ENABLE
must set CONFIG_BOARD_ETC_ROMFS_PASSWD_PASSWORD to a non-empty string
of at least 8 characters. The build now fails with an explicit error if
this config is left empty. To fix: run 'make menuconfig' and navigate to:
  Board Selection --->
    Auto-generate /etc/passwd at build time --->
      Admin password

Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
@Abhishek-2808
Copy link
Copy Markdown
Author

@acassis, That's a very good catch!!! I have updated the PR to make root instead of admin as many folks including me liked this idea...
Also, all the commits now start with "!", and error message is improved.
Thanks. :)

Copy link
Copy Markdown
Contributor

@acassis acassis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Abhishek-2808 I found many please where "admin" still used, please double check if there are more places

USERNAME: admin
PASSWORD: Administrator
* ``CONFIG_BOARD_ETC_ROMFS_PASSWD_ENABLE=y``
* ``CONFIG_BOARD_ETC_ROMFS_PASSWD_USER`` (default: ``admin``)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update here too

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! fixed this in the latest commit, please check.

nsh> cat /etc/passwd
admin:8Tv+Hbmr3pLVb5HHZgd26D:0:0:/
CONFIG_BOARD_ETC_ROMFS_PASSWD_ENABLE=y
CONFIG_BOARD_ETC_ROMFS_PASSWD_USER (default: admin)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

admin:8Tv+Hbmr3pLVb5HHZgd26D:0:0:/
* ``CONFIG_BOARD_ETC_ROMFS_PASSWD_ENABLE=y``
* ``CONFIG_NSH_CONSOLE_LOGIN=y`` (required, otherwise login is not enforced)
* ``CONFIG_BOARD_ETC_ROMFS_PASSWD_USER`` (default: ``admin``)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


$ ./nuttx
NuttShell (NSH) NuttX-<version>
nsh login: admin
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Abhishek Mishra added 2 commits April 12, 2026 18:35
Migrate boards from static /etc/passwd files to build-time generation:

* Remove static etc/passwd files from SIM and ESP32-C3-legacy boards
* Update board configurations to enable BOARD_ETC_ROMFS_PASSWD_ENABLE
* Configure SIM board with login demo user (root/Administrator)
* Update board build rules to use newly generated passwd files
* Remove CMakeLists.txt dependency on static passwd in SIM
* Update MOTD string from username=admin to username=root

This completes the infrastructure migration for boards supporting
login functionality.

BREAKING CHANGE: The static etc/passwd files have been removed from
  boards/sim/sim/sim/src/etc/passwd
  boards/risc-v/esp32c3-legacy/esp32c3-legacy-devkit/src/etc/passwd
These boards now require CONFIG_BOARD_ETC_ROMFS_PASSWD_ENABLE=y and a
configured password. Any board carrying a custom static passwd file must
set RCRAWS to exclude etc/passwd and manage credentials via the new
Kconfig options or provide their own passwd generation. To fix: run
'make menuconfig' and navigate to:
  Board Selection --->
    Auto-generate /etc/passwd at build time --->
      Admin password

Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
Document the new mkpasswd-based password generation system and its
integration with the build process.

Changes:
* Add comprehensive mkpasswd tool documentation to components/tools
* Update SIM board docs to explain generated passwd workflow
* Update ESP32-C3-legacy board docs for passwd generation
* Update RX65N board docs with credential handling guidance
* Document how to configure and use BOARD_ETC_ROMFS_PASSWD_* options
* Explain security benefits of build-time generation vs static files
* Update all doc examples from default username "admin" to "root"

BREAKING CHANGE: Boards using static /etc/passwd files in ETC_ROMFS
must migrate to the new build-time generation workflow documented in
Documentation/components/tools/index.rst. The old static passwd files
are no longer present in migrated boards; boards that relied on them
will fail to build until credentials are configured via Kconfig.

Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Build system Board: risc-v Board: simulator Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants