From 04fbbbb076736b8bb769fb72a2cb7eff3fe7070b Mon Sep 17 00:00:00 2001 From: Anthony Date: Tue, 31 Oct 2023 00:13:29 +0800 Subject: [PATCH] Own config and symlinks --- add-sftp.sh | 21 ++++++++++++--------- manifest.jps | 8 ++------ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/add-sftp.sh b/add-sftp.sh index 6586927..6a1e3ee 100644 --- a/add-sftp.sh +++ b/add-sftp.sh @@ -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 diff --git a/manifest.jps b/manifest.jps index 93a35b1..80716a9 100644 --- a/manifest.jps +++ b/manifest.jps @@ -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