Last active
November 15, 2023 18:23
-
-
Save rpetit3/031a89359ace9ff8475147e39f8eeecf to your computer and use it in GitHub Desktop.
create-admin - simple script to create admin users on Debian
This file contains 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-admin NEW_USERNAME" | |
echo "" | |
echo "Example Command" | |
echo "create-admin robert_petit" | |
echo "" | |
exit | |
fi | |
USERNAME=$1 | |
PASSWORD=$(head /dev/urandom | md5sum | cut -c1-10) | |
# Add user | |
useradd \ | |
--shell /bin/bash \ | |
--user-group \ | |
--groups sudo,docker \ | |
--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