Skip to content

Conversation

@brendandebeasi
Copy link

@brendandebeasi brendandebeasi commented Jan 21, 2026

linuxserver.io


  • I have read the contributing guideline and understand that I have made the correct modifications

Description:

Fix grep pattern in init-adduser script to use exact username matching by adding a colon delimiter.

Change: grep -q "^${USER_NAME}"grep -q "^${USER_NAME}:"

Benefits of this PR and context:

The current check incorrectly matches usernames that are prefixes of existing system users. For example, USER_NAME=b matches the bin user because grep "^b" matches bin:x:1:1:....

This causes containers to halt with a false positive error:

*** USER_NAME cannot be set to an user that already exists in /etc/passwd. Halting init. ***

The /etc/passwd format is username:password:uid:gid:..., so matching ^username: ensures exact username field matching.

closes #118

How Has This Been Tested?

Verified the regex logic:

  • echo "bin:x:1:1:bin" | grep -q "^b" → matches (current behavior, incorrect)
  • echo "bin:x:1:1:bin" | grep -q "^b:" → no match (fixed behavior, correct)
  • echo "bin:x:1:1:bin" | grep -q "^bin:" → matches (correct, exact match)

Source / References:

The grep pattern `^${USER_NAME}` incorrectly matches usernames that
are prefixes of existing users. For example, USER_NAME=b matches the
'bin' user, causing the container to halt with a false positive.

Adding a colon after USER_NAME ensures exact username matching:
`^${USER_NAME}:` only matches the exact username field.

closes linuxserver#118
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Thanks for opening this pull request! Be sure to follow the pull request template!

@LinuxServer-CI
Copy link
Contributor

I am a bot, here are the test results for this PR:
https://ci-tests.linuxserver.io/lspipepr/openssh-server/10.2_p1-r0-pkg-4d3c8518-dev-155cbf4efdf60fed7b2af52b064409156fcf3c44-pr-119/index.html
https://ci-tests.linuxserver.io/lspipepr/openssh-server/10.2_p1-r0-pkg-4d3c8518-dev-155cbf4efdf60fed7b2af52b064409156fcf3c44-pr-119/shellcheck-result.xml

Tag Passed
amd64-10.2_p1-r0-pkg-4d3c8518-dev-155cbf4efdf60fed7b2af52b064409156fcf3c44-pr-119
arm64v8-10.2_p1-r0-pkg-4d3c8518-dev-155cbf4efdf60fed7b2af52b064409156fcf3c44-pr-119

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

[BUG] USER_NAME=b falsely matches 'bin' user due to loose grep pattern

2 participants