Operations 5 min read

Auto‑Create a Boot‑Time User by Editing /etc/shadow and /etc/passwd in Buildroot

This guide explains how to automatically create a user on boot in a Buildroot‑based embedded Linux system by manually adding the user, copying the resulting /etc/shadow and /etc/passwd entries into the root filesystem, rebuilding the image, and handling time‑related password issues.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Auto‑Create a Boot‑Time User by Editing /etc/shadow and /etc/passwd in Buildroot

Introduction

The project requires automatically creating a specific user with a password immediately after the device boots. The vendor SDK only provides an adduser command that prompts for password entry, making simple scripting impossible.

Environment

sdk: 复旦微
Buildroot 2018.02.3

Steps

1. Add user manually with adduser

On the development board run # adduser ftp. The command fails to create a home directory, then asks for a password, which must be entered twice. After success the system updates /etc/shadow and /etc/passwd with the new user entry.

# adduser ftp
adduser: /home/ftp: No such file or directory
Changing password for ftp
New password:
Bad password: too weak
Retype password:
passwd: password for ftp changed by root

The relevant lines added are:

# cat /etc/shadow
…
ftp:$1$AQb2UA9p$mX8fQskQJcHm0t4QlVk4A1:0:0:99999:7:::
# cat /etc/passwd
…
ftp:x:1000:1000:Linux User,,,:/home/ftp:/bin/sh

2. Copy the modified files into the Buildroot target

Place the edited shadow and passwd files into the SDK’s Buildroot output directory:

/home/peng/xxx/work/xxx/sdk/buildroot-2018.02.3/output/target/etc

Verify the files are present with correct permissions:

peng@ubuntu:~/work/xxx/sdk/buildroot-2018.02.3/output/target/etc$ ls -l passwd shadow
-rwxr--r-- 1 peng peng 339 Nov 15 17:24 passwd
-rwx------ 1 peng peng 242 Nov 15 17:24 shadow

Edit the two files with root privileges to include the new user entries.

Build and Flash

Re‑compile the SDK, flash the image, and reboot. The device now accepts login with the ftp user and the password set earlier.

Important Note

If the login fails, it may be because the system clock is still set to the Unix epoch (1970), which renders the password hash invalid. Set the date manually before login, e.g.: date -s '2024-11-23 15:12' This command can be added to the system’s init script ( sdk/buildroot-2018.02.3/output/target/etc/init.d/rcS) to run automatically at boot.

automationshadowpasswdbuildrootuser-managementembedded-linux
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.