Skip to content

Instantly share code, notes, and snippets.

@rpetit3
Created November 15, 2023 18:26
Show Gist options
  • Save rpetit3/bca037375aa55148a51ebe334224e699 to your computer and use it in GitHub Desktop.
Save rpetit3/bca037375aa55148a51ebe334224e699 to your computer and use it in GitHub Desktop.
create-user - simple script to create a basic user in Debian
#! /bin/bash
if [[ $# == 0 ]]; then
echo ""
echo "create-user NEW_USERNAME"
echo ""
echo "Example Command"
echo "create-user robert_petit"
echo ""
exit
fi
USERNAME=$1
PASSWORD=$(head /dev/urandom | md5sum | cut -c1-10)
# Add user
useradd \
--shell /bin/bash \
--user-group \
--home-dir /home/${USERNAME} \
--create-home \
--password $(echo ${PASSWORD} | openssl passwd -1 -stdin) \
${USERNAME}
# set password to expire on first login
chage -d 0 ${USERNAME}
echo "Username: ${USERNAME}"
echo "One-Time Password: ${PASSWORD}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment