Skip to content

Conversation

@kjeldflarup
Copy link

I get my UID from an AD which uses very large number.
adduser and addgroup commands does not accept these large numbers (at least not in this alpine version)

adduser: number 1304035270 is not in 0..256000 range
addgroup: number 1304000513 is not in 0..256000 range

When creating users and groups change to useradd and groupadd

Signed-off-by: Kjeld Flarup kfa@deif.com

…256000

Signed-off-by: Kjeld Flarup <kfa@deif.com>
@MarvAmBass
Copy link
Member

thanks for your work -> great idea with just installing those utils (it didn't occure to me 😄)

I need to look into it and test it before I can merge it (to many users to risk it) but looks really nice!

thanks and kind regards

Marvin

Choose a reason for hiding this comment

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

@kjeldflarup, you missed addgroup on L113.

-addgroup "$ACCOUNT_NAME" "$GRP"
+usermod -aG "$GRP" "$ACCOUNT_NAME"

Copy link
Author

@kjeldflarup kjeldflarup Oct 27, 2024

Choose a reason for hiding this comment

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

You are right. I just pushed a commit with that change, but I did not test it :-)
But according to my man page, this addgroup command also seems to be incorrect, or at least not portable.

Choose a reason for hiding this comment

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

I did not test it :-)

I tested it on Ubutu and Alipine Linux, it works as expected. 😉

But according to my man page, this addgroup command also seems to be incorrect, or at least not portable.

The old adduser command works on Alpine Linux, where it is installed as part of Busybox which is quite limited and uses different options from its other implementations.

Signed-off-by: Kjeld Flarup <kfa@deif.com>
Copy link

@ottobolyos ottobolyos left a comment

Choose a reason for hiding this comment

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

@kjeldflarup, I have found a few issues still. 😉

Here is a table with the options used by adduser in this repository with corresponding useradd options.

adduser useradd Description from adduser
-H -M Don't create home directory
-D n/a Don't assign a password
-s SHELL -s SHELL Login shell
-u UID -u UID User id

As for -D from adduser, for useradd it is not required, as this is the default in useradd. Excerpt from man useradd on -p, --password PASSWORD:

Without this option, the new account will be locked and with no password defined, i.e. a single exclamation mark in the respective field of /etc/shadow. This is a state where the user won't be able to access the account or to define a password himself.

then
echo ">> ACCOUNT: adding account: $ACCOUNT_NAME with UID: $ACCOUNT_UID"
adduser -D -H -u "$ACCOUNT_UID" -s /bin/false "$ACCOUNT_NAME"
useradd -u "$ACCOUNT_UID" -s /bin/false "$ACCOUNT_NAME"

Choose a reason for hiding this comment

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

You are missing -M (Do not create the user's home directory, even if the system wide setting from /etc/login.defs (CREATE_HOME) is set to yes.).

Suggested change
useradd -u "$ACCOUNT_UID" -s /bin/false "$ACCOUNT_NAME"
useradd -Mu "$ACCOUNT_UID" -s /bin/false "$ACCOUNT_NAME"

Choose a reason for hiding this comment

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

And we probably want to add -N to not create user group. 🤔

if [ "$PASSWORD_1" == "$PASSWORD_2" ] && [ "$PASSWORD_1" != "" ] && [ "$USERNAME" != "" ]
then
adduser -D -H -s /bin/false "$USERNAME" 2> /dev/null >/dev/null
useradd -u "$ACCOUNT_UID" -s /bin/false "$ACCOUNT_NAME" 2> /dev/null >/dev/null

Choose a reason for hiding this comment

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

Here you have a mistake: ACCOUNT_UID is not defined in this file. And you are missing -M.

Suggested change
useradd -u "$ACCOUNT_UID" -s /bin/false "$ACCOUNT_NAME" 2> /dev/null >/dev/null
useradd -Ms /bin/false "$ACCOUNT_NAME" 2> /dev/null >/dev/null

else
echo ">> ACCOUNT: adding account: $ACCOUNT_NAME"
adduser -D -H -s /bin/false "$ACCOUNT_NAME"
useradd -s /bin/false "$ACCOUNT_NAME"

Choose a reason for hiding this comment

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

Suggested change
useradd -s /bin/false "$ACCOUNT_NAME"
useradd -Ms /bin/false "$ACCOUNT_NAME"

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants