timmy gist felülvizsgálása 10 months ago. Revízióhoz ugrás
Nincsenek változtatások
timmy gist felülvizsgálása 10 months ago. Revízióhoz ugrás
Nincsenek változtatások
timmy gist felülvizsgálása 1 year ago. Revízióhoz ugrás
1 file changed, 25 insertions
create_user_and_configure_sudo.sh(fájl létrehozva)
| @@ -0,0 +1,25 @@ | |||
| 1 | + | #!/bin/bash | |
| 2 | + | ||
| 3 | + | # Check if a username was provided as an argument | |
| 4 | + | if [ $# -ne 1 ]; then | |
| 5 | + | echo "Error: Please provide a username as an argument." | |
| 6 | + | exit 1 | |
| 7 | + | fi | |
| 8 | + | ||
| 9 | + | # Get the username from the argument | |
| 10 | + | username="$1" | |
| 11 | + | ||
| 12 | + | # Prompt for the user's password | |
| 13 | + | read -s -p "Enter password for $username: " password | |
| 14 | + | echo | |
| 15 | + | ||
| 16 | + | # Add the user and set the password | |
| 17 | + | sudo adduser --home /home/$username --gecos "" --disabled-password $username | |
| 18 | + | echo "$username:$password" | sudo chpasswd | |
| 19 | + | ||
| 20 | + | # Add the user to the sudo group | |
| 21 | + | sudo usermod -aG sudo $username | |
| 22 | + | ||
| 23 | + | # Configure the sudoers file to allow the user to use sudo without a password | |
| 24 | + | echo "$username ALL=(ALL:ALL) ALL" | sudo tee -a /etc/sudoers | |
| 25 | + | echo "$username ALL=NOPASSWD: ALL" | sudo tee -a /etc/sudoers | |
Újabb
Régebbi