usermod equivalent for Alpine Linux

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?


Solution 1:

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.