Created
November 15, 2023 18:26
-
-
Save rpetit3/bca037375aa55148a51ebe334224e699 to your computer and use it in GitHub Desktop.
create-user - simple script to create a basic user in Debian
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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