Create Add Users function

This commit is contained in:
VetheonGames 2024-05-24 08:34:29 -06:00
parent ac063405b3
commit b54a7e50f3

View File

@ -135,6 +135,39 @@ run_additional_setup() {
fi
}
# Function to add additional users
add_users() {
log "Do you want to add additional users? (yes/no)"
read -r ADD_USERS
while [[ $ADD_USERS == "yes" ]]; do
log "Enter the username:"
read -r USERNAME
log "Enter the password:"
read -r -s PASSWORD
useradd -m "$USERNAME"
echo "$USERNAME:$PASSWORD" | chpasswd
log "Do you want to grant sudo access to $USERNAME? (yes/no)"
read -r GRANT_SUDO
if [[ $GRANT_SUDO == "yes" ]]; then
usermod -aG sudo "$USERNAME"
log "$USERNAME has been granted sudo access."
fi
log "Do you want to add a public key for $USERNAME? (yes/no)"
read -r ADD_PUBLIC_KEY
if [[ $ADD_PUBLIC_KEY == "yes" ]]; then
log "Please enter the public key:"
read -r PUBLIC_KEY
su - "$USERNAME" -c "mkdir -p ~/.ssh && echo '$PUBLIC_KEY' >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys && chmod 700 ~/.ssh"
log "Public key added for $USERNAME."
fi
log "Do you want to add another user? (yes/no)"
read -r ADD_USERS
done
}
# Main script execution
detect_os
log "Detected OS: $OS, Package Manager: $PKG_MANAGER"
@ -176,3 +209,6 @@ log "Setup complete. Summary of actions performed:"
# Run additional setup if requested
run_additional_setup
# Add additional users if requested
add_users