You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
549 B
26 lines
549 B
#!/bin/sh |
|
|
|
# User information |
|
USERNAME="$1" |
|
PASSWORD="$2" |
|
USER_DIRECTORY="./users/$USERNAME" |
|
|
|
# Check if the username and password are provided |
|
if [ -z "$USERNAME" ] || [ -z "$PASSWORD" ]; then |
|
echo "Username and password are required." |
|
exit 1 |
|
fi |
|
|
|
# Create the user (-m creates their home directory) |
|
sudo useradd -m "$USERNAME" |
|
|
|
# Check if the user was created successfully |
|
if [ $? -ne 0 ]; then |
|
echo "Failed to create user." |
|
exit 1 |
|
fi |
|
|
|
# Set the password |
|
echo "$USERNAME:$PASSWORD" | sudo chpasswd |
|
|
|
echo "User $USERNAME created successfully." |