Skip to content

Instantly share code, notes, and snippets.

@kaashmonee
Created September 19, 2018 01:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaashmonee/ac7ddd722c1010f2b71e8c292a4f158f to your computer and use it in GitHub Desktop.
Save kaashmonee/ac7ddd722c1010f2b71e8c292a4f158f to your computer and use it in GitHub Desktop.
Creates a user on a linux system using the first command line arg, sets a temporary password, and adds them to the root and Docker groups.
#!/bin/bash
# Ensure that script is being run as root.
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root!"
exit 1
fi
# Getting username from cmd line
username=$1
# Creating a new user from username
echo "Creating a new user with name: $username"
echo "Type the following as the temporary password: <TEMP_PASS_HERE>"
adduser $username
# force user to change their password upon login
chage -d 0 $username
# Adding user to sudo group
usermod -aG sudo $username
# Adding user to dockergroup
usermod -aG docker $username
echo "Please ensure that $username is in the appropriate groups:"
groups $username
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment