Sometimes it is nice to have a simple way to "reproduce users" on a system
i.e. my server is connected to LDAP and has users / groups defined. I want to be able to create the same UIDs/GIDs without joining to the LDAP server.
This script is designed to help.
- Run it on the server where users are defined.
- It loops through users, code-generating a shell script that can "recreate" those users with proper UID/GID
- Save the output script and transport it to where you need it (docker containers, etc.)
Ok. In an ideal world, we probably wouldn't need this. But in all cases ( 😉 ), "ideal world" != "real world"
# make script executable
chmod +x generate_user_creation.sh
# basic usage
# ./generate_user_creation.sh << space delimited usernames >>
./generate_user_creation.sh colearendt other-user
# to see only the script output
./generate_user_creation.sh colearendt other-user 2>/dev/null
# to build the generation script and see logs in the terminal
./generate_user_creation.sh colearendt other-user > my_script.sh
- Users who do not exist / have an error will be skipped
useradd
/groupadd
commands for existing users / groups will error, butset -e
is not in use, so the output script will continuestdout
is for the script,stderr
is for logging- I have not tested thorougly with invalid user / group names. Add parameters / customize as needed for your own case!