Own config and symlinks

main
Anthony 2023-10-31 00:13:29 +08:00
parent 9c21c3e302
commit 04fbbbb076
2 changed files with 14 additions and 15 deletions

View File

@ -6,8 +6,12 @@ echo "Script started" >> /home/jelastic/add-sftp-user-addon/script_output.log
USERNAME="user$(shuf -i 10000-99999 -n 1)"
PASSWORD=$(openssl rand -base64 12)
# Append the username to the ROOT_DIRECTORY to ensure a unique home directory for each user
ROOT_DIRECTORY="/var/www/webroot/ROOT/$USERNAME"
# User's home directory
USER_HOME="/home/$USERNAME"
# The shared directory
ROOT_DIRECTORY="/var/www/webroot/ROOT"
# Get the group ownership of the ROOT_DIRECTORY
ROOT_GROUP=$(stat -c '%G' $ROOT_DIRECTORY)
# Check if user already exists
if id "$USERNAME" &>/dev/null; then
@ -15,20 +19,19 @@ if id "$USERNAME" &>/dev/null; then
exit 1
fi
# Create user
useradd -m -d $ROOT_DIRECTORY $USERNAME
# Create user with their own home directory
useradd -m $USERNAME
if [ $? -ne 0 ]; then
echo "Failed to create user $USERNAME." >> /home/jelastic/add-sftp-user-addon/script_output.log
exit 1
fi
echo "$USERNAME:$PASSWORD" | chpasswd
# Set user's group to both litespeed and root
usermod -aG litespeed,root $USERNAME
# Create a symlink in the user's home directory pointing to the shared ROOT_DIRECTORY
ln -s $ROOT_DIRECTORY $USER_HOME/ROOT
# Adjust permissions for the user to write to the ROOT_DIRECTORY
chown $USERNAME:root $ROOT_DIRECTORY
chmod 775 $ROOT_DIRECTORY
# Set user's group to the ROOT_GROUP and any other groups as needed (e.g., root)
usermod -aG $ROOT_GROUP,root $USERNAME
HOSTNAME=$(hostname -f)
echo "Script completed for user $USERNAME with hostname $HOSTNAME" >> /home/jelastic/add-sftp-user-addon/script_output.log

View File

@ -11,13 +11,9 @@ settings:
inputType: text
name: root_directory
caption: Root Directory
default: "/var/www/webroot/ROOT/{username}/"
default: "/var/www/webroot/ROOT/"
description: "A user-specific directory will be created under this path."
required: false
- type: checkbox
name: agree_creation
caption: I agree to the creation of a folder and SFTP account.
required: true
required: false
- type: checkbox
name: enable_ssh
caption: Also enable SSH access