Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # This script creates a new user named "Awire" with a home directory
- # and adds them to common groups, simulating permissions given by an installer.
- # IMPORTANT:
- # - This script requires root privileges (run with sudo).
- # - You will be prompted to set a password for Awire during execution.
- # - Always review scripts before running them, especially those that modify user accounts.
- echo "Starting user creation process for 'Awire'..."
- # Step 1: Check for root privileges
- if [[ $EUID -ne 0 ]]; then
- echo "This script must be run as root."
- echo "Please run with: sudo ./create_awire_user.sh"
- exit 1
- fi
- # Step 2: Define username
- USERNAME="Awire"
- # Step 3: Check if the user already exists
- if id "$USERNAME" &>/dev/null; then
- echo "User '$USERNAME' already exists. Aborting."
- exit 0
- fi
- # Step 4: Create the new user with a home directory
- # -m: Create the user's home directory if it does not exist.
- # -s /bin/bash: Set the default shell to Bash.
- echo "Creating user '$USERNAME' with home directory..."
- useradd -m -s /bin/bash "$USERNAME" || { echo "Error: Failed to create user '$USERNAME'. Exiting."; exit 1; }
- echo "User '$USERNAME' created."
- # Step 5: Set password for the new user
- echo "Please set a password for user '$USERNAME':"
- passwd "$USERNAME" || { echo "Error: Failed to set password for '$USERNAME'. Exiting."; exit 1; }
- echo "Password set for '$USERNAME'."
- # Step 6: Add the user to common groups for a standard desktop user
- # These groups grant permissions for various hardware and system functionalities.
- # The 'sudo' group is included to give Awire administrator privileges (if desired, remove if not).
- echo "Adding user '$USERNAME' to common groups..."
- COMMON_GROUPS=(
- sudo # For administrative privileges (e.g., using sudo)
- adm # System monitoring
- cdrom # Access to CD/DVD drives
- dip # Dial-up access (less common now but still standard)
- lpadmin # Printer administration
- plugdev # Plug-and-play devices (USB drives, etc.)
- sambashare # Sharing files via Samba (if installed)
- render # Graphics rendering (for GPU access)
- netdev # Network device management
- audio # Audio device access
- video # Video device access
- input # Input devices (keyboard, mouse)
- staff # General staff group
- systemd-journal # Access to systemd journal logs
- # Add other groups as needed, e.g., 'vboxusers' for VirtualBox, 'docker' for Docker.
- )
- for group in "${COMMON_GROUPS[@]}"; do
- if getent group "$group" &>/dev/null; then
- echo " Adding '$USERNAME' to group '$group'..."
- usermod -aG "$group" "$USERNAME" || { echo "Warning: Failed to add '$USERNAME' to group '$group'."; }
- else
- echo " Group '$group' does not exist. Skipping."
- fi
- done
- echo "User '$USERNAME' added to specified groups."
- echo "User '$USERNAME' created and configured successfully!"
- echo "Awire can now log in using the password you provided."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement