35 lines
798 B
Bash
35 lines
798 B
Bash
#!/bin/bash
|
|
|
|
# Generate random username and password
|
|
USERNAME="user$(shuf -i 10000-99999 -n 1)"
|
|
PASSWORD=$(openssl rand -base64 12)
|
|
|
|
ROOT_DIRECTORY="/var/www/webroot/ROOT"
|
|
|
|
# Check if user already exists
|
|
if id "$USERNAME" &>/dev/null; then
|
|
echo "User $USERNAME already exists."
|
|
exit 1
|
|
fi
|
|
|
|
# Create user and set password
|
|
useradd -m -d $ROOT_DIRECTORY $USERNAME
|
|
if [ $? -ne 0 ]; then
|
|
echo "Failed to create user $USERNAME."
|
|
exit 1
|
|
fi
|
|
echo "$USERNAME:$PASSWORD" | chpasswd
|
|
|
|
# Set user's group to litespeed (or another group with SFTP permissions)
|
|
usermod -aG litespeed $USERNAME
|
|
|
|
# Get the hostname
|
|
HOSTNAME=$(hostname -f)
|
|
|
|
# Print the credentials
|
|
echo "SFTP User Created Successfully!"
|
|
echo "Username: $USERNAME"
|
|
echo "Password: $PASSWORD"
|
|
echo "SFTP Host: $HOSTNAME"
|
|
echo "Port: 22"
|