Advertisement
AWIRE9966_09onpc

AddMe

Jul 6th, 2025
5
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # This script creates a new user named "Awire" with a home directory
  4. # and adds them to common groups, simulating permissions given by an installer.
  5.  
  6. # IMPORTANT:
  7. # - This script requires root privileges (run with sudo).
  8. # - You will be prompted to set a password for Awire during execution.
  9. # - Always review scripts before running them, especially those that modify user accounts.
  10.  
  11. echo "Starting user creation process for 'Awire'..."
  12.  
  13. # Step 1: Check for root privileges
  14. if [[ $EUID -ne 0 ]]; then
  15. echo "This script must be run as root."
  16. echo "Please run with: sudo ./create_awire_user.sh"
  17. exit 1
  18. fi
  19.  
  20. # Step 2: Define username
  21. USERNAME="Awire"
  22.  
  23. # Step 3: Check if the user already exists
  24. if id "$USERNAME" &>/dev/null; then
  25. echo "User '$USERNAME' already exists. Aborting."
  26. exit 0
  27. fi
  28.  
  29. # Step 4: Create the new user with a home directory
  30. # -m: Create the user's home directory if it does not exist.
  31. # -s /bin/bash: Set the default shell to Bash.
  32. echo "Creating user '$USERNAME' with home directory..."
  33. useradd -m -s /bin/bash "$USERNAME" || { echo "Error: Failed to create user '$USERNAME'. Exiting."; exit 1; }
  34. echo "User '$USERNAME' created."
  35.  
  36. # Step 5: Set password for the new user
  37. echo "Please set a password for user '$USERNAME':"
  38. passwd "$USERNAME" || { echo "Error: Failed to set password for '$USERNAME'. Exiting."; exit 1; }
  39. echo "Password set for '$USERNAME'."
  40.  
  41. # Step 6: Add the user to common groups for a standard desktop user
  42. # These groups grant permissions for various hardware and system functionalities.
  43. # The 'sudo' group is included to give Awire administrator privileges (if desired, remove if not).
  44. echo "Adding user '$USERNAME' to common groups..."
  45. COMMON_GROUPS=(
  46. sudo # For administrative privileges (e.g., using sudo)
  47. adm # System monitoring
  48. cdrom # Access to CD/DVD drives
  49. dip # Dial-up access (less common now but still standard)
  50. lpadmin # Printer administration
  51. plugdev # Plug-and-play devices (USB drives, etc.)
  52. sambashare # Sharing files via Samba (if installed)
  53. render # Graphics rendering (for GPU access)
  54. netdev # Network device management
  55. audio # Audio device access
  56. video # Video device access
  57. input # Input devices (keyboard, mouse)
  58. staff # General staff group
  59. systemd-journal # Access to systemd journal logs
  60. # Add other groups as needed, e.g., 'vboxusers' for VirtualBox, 'docker' for Docker.
  61. )
  62.  
  63. for group in "${COMMON_GROUPS[@]}"; do
  64. if getent group "$group" &>/dev/null; then
  65. echo " Adding '$USERNAME' to group '$group'..."
  66. usermod -aG "$group" "$USERNAME" || { echo "Warning: Failed to add '$USERNAME' to group '$group'."; }
  67. else
  68. echo " Group '$group' does not exist. Skipping."
  69. fi
  70. done
  71. echo "User '$USERNAME' added to specified groups."
  72.  
  73. echo "User '$USERNAME' created and configured successfully!"
  74. echo "Awire can now log in using the password you provided."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement