Skip to content

Instantly share code, notes, and snippets.

@ravihara
Created November 10, 2017 11:06
Show Gist options
  • Save ravihara/58e4f51dc0913cd2e1cbe6df75540759 to your computer and use it in GitHub Desktop.
Save ravihara/58e4f51dc0913cd2e1cbe6df75540759 to your computer and use it in GitHub Desktop.
Shell script to add a system user
#!/bin/bash -e
# Add a system user in Linux
if [ $UID -ne 0 ]; then
echo "You must be a root / superuser, in order to run this script. $(basename $0) aborted."
exit 1
fi
if [ $# -ne 3 ]; then
echo "Usage: $(basename $0) <user-name> <user-home> <gecos-string>"
exit 2
fi
echo "Adding system-user $1 with home-dir at $2 and description $3 ..."
adduser --system --shell /bin/bash --gecos '$3' --group --disabled-password --home $2 $1
echo "DONE."
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment