Operations 4 min read

Auto‑Create a User on Boot by Editing rootfs shadow & passwd Files

This guide explains how to automatically add a user with a preset password on an embedded Linux device at boot by manually creating the user once, extracting its entries from /etc/shadow and /etc/passwd, and inserting those entries into the buildroot target filesystem before flashing.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Auto‑Create a User on Boot by Editing rootfs shadow & passwd Files

Introduction

The project requires a user account to exist immediately after power‑on, but the vendor‑provided SDK only offers an adduser command that prompts for password input, making pure scripting impossible. To avoid adding the heavy expect tool, the solution modifies the root filesystem directly.

Environment

sdk: 复旦微
Buildroot 2018.02.3

Steps

1. Manually add the user with adduser

On the development board, run:

# 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 command updates two files:

/etc/shadow
/etc/passwd

Entries are appended at the end of each file. Example excerpts:

# 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 extracted entries into the SDK’s buildroot output

Place the modified shadow and passwd files into the target rootfs directory:

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

Verify the files exist with proper 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

Use root privileges to edit the two files, inserting the previously captured lines for the new user.

After rebuilding and flashing the image, the device boots with the ftp user ready for login.

Note

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

AutomationEmbedded Linuxrootfsbuildroot
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.