usermod equivalent for Alpine Linux

7

I'm building a Docker container, and I need to add my user to a group. usermod is not available in Alpine Linux by default. Apparently, you can add shadow from apk to install usermod, but I would prefer to not install additional packages.

Is there an alternative way to add a user to a group, or an equivalent tool to usermod available in Alpine?

Zak

Posted 2019-01-17T17:13:03.273

Reputation: 171

Have you seen this? Basically adding environment variables for UID and GID when initializing. – JakeGould – 2019-01-17T17:20:32.113

2Why not simply modify the /etc/group file directly? – davidgo – 2019-01-17T18:12:09.373

@davidgo Some people don’t know you can just edit it like that but it’s a good solution. Would need to be scriptable via sed or something like that. – JakeGould – 2019-01-17T21:09:56.810

Answers

8

You should be able to use the built-in addgroup command to add the user to a given group:

$ addgroup --help
BusyBox v1.29.3 (2019-01-24 07:45:07 UTC) multi-call binary.

Usage: addgroup [-g GID] [-S] [USER] GROUP

Add a group or add a user to a group

        -g GID  Group id
        -S      Create a system group

So running addgroup ${USER} ${GROUP} should update /etc/groups without needing to edit the file directly.

tzrlk

Posted 2019-01-17T17:13:03.273

Reputation: 181