I'm a newbie to bash scripting, and I'm trying to make a script to setup some basic security on a ubuntu server. I have the following so far:
group="sudo"
read -p "Set new sudo user's name (Please try to avoid admin or administrator, some hosts have these reserved): " new_sudo_user_name
if [ -z "$(getent passwd $new_sudo_user_name)" ]; then
echo "user does NOT exist."
else
echo "user DOES exist."
fi
echo "Please enter the new password:"
read -s password1
echo "Please repeat the new password:"
read -s password2
if [ $password1 != $password2 ]; then
echo "Passwords do not match"
exit
fi
sudo su -c "useradd $new_sudo_user_name -s /bin/bash -m -aG $group"
Essentially, what I'd like for it to do is to, upon checking if the username exists already to automatically re-ask for a new username if it is found to already exist. Is this possible? If so, what is best practice to accomplish this task?
Appreciate the help in advance :)