Files
alfred-preferences/Alfred.alfredpreferences/snippets/script/create_user_and_configure_sudo.sh [34C8CA5B-0065-4DA5-97C1-EA88A872D5A1].json
2026-03-26 09:22:38 +08:00

8 lines
1.0 KiB
JSON

{
"alfredsnippet" : {
"snippet" : "echo '#!\/bin\/bash\n\n# Check if a username was provided as an argument\nif [ $# -ne 1 ]; then\n echo \"Error: Please provide a username as an argument.\"\n exit 1\nfi\n\n# Get the username from the argument\nusername=\"$1\"\n\n# Prompt for the user'\\''s password\nread -s -p \"Enter password for $username: \" password\necho\n\n# Add the user and set the password\nsudo adduser --home \/home\/$username --gecos \"\" --disabled-password $username\necho \"$username:$password\" | sudo chpasswd\n\n# Add the user to the sudo group\nsudo usermod -aG sudo $username\n\n# Configure the sudoers file to allow the user to use sudo without a password\necho \"$username ALL=(ALL:ALL) ALL\" | sudo tee -a \/etc\/sudoers\necho \"$username ALL=NOPASSWD: ALL\" | sudo tee -a \/etc\/sudoers' > create_user_and_configure_sudo.sh\n\nchmod +x create_user_and_configure_sudo.sh\n",
"uid" : "34C8CA5B-0065-4DA5-97C1-EA88A872D5A1",
"name" : "create_user_and_configure_sudo.sh",
"keyword" : "script"
}
}