Own config and symlinks
parent
9c21c3e302
commit
04fbbbb076
21
add-sftp.sh
21
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)"
|
USERNAME="user$(shuf -i 10000-99999 -n 1)"
|
||||||
PASSWORD=$(openssl rand -base64 12)
|
PASSWORD=$(openssl rand -base64 12)
|
||||||
|
|
||||||
# Append the username to the ROOT_DIRECTORY to ensure a unique home directory for each user
|
# User's home directory
|
||||||
ROOT_DIRECTORY="/var/www/webroot/ROOT/$USERNAME"
|
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
|
# Check if user already exists
|
||||||
if id "$USERNAME" &>/dev/null; then
|
if id "$USERNAME" &>/dev/null; then
|
||||||
|
@ -15,20 +19,19 @@ if id "$USERNAME" &>/dev/null; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create user
|
# Create user with their own home directory
|
||||||
useradd -m -d $ROOT_DIRECTORY $USERNAME
|
useradd -m $USERNAME
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Failed to create user $USERNAME." >> /home/jelastic/add-sftp-user-addon/script_output.log
|
echo "Failed to create user $USERNAME." >> /home/jelastic/add-sftp-user-addon/script_output.log
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "$USERNAME:$PASSWORD" | chpasswd
|
echo "$USERNAME:$PASSWORD" | chpasswd
|
||||||
|
|
||||||
# Set user's group to both litespeed and root
|
# Create a symlink in the user's home directory pointing to the shared ROOT_DIRECTORY
|
||||||
usermod -aG litespeed,root $USERNAME
|
ln -s $ROOT_DIRECTORY $USER_HOME/ROOT
|
||||||
|
|
||||||
# Adjust permissions for the user to write to the ROOT_DIRECTORY
|
# Set user's group to the ROOT_GROUP and any other groups as needed (e.g., root)
|
||||||
chown $USERNAME:root $ROOT_DIRECTORY
|
usermod -aG $ROOT_GROUP,root $USERNAME
|
||||||
chmod 775 $ROOT_DIRECTORY
|
|
||||||
|
|
||||||
HOSTNAME=$(hostname -f)
|
HOSTNAME=$(hostname -f)
|
||||||
echo "Script completed for user $USERNAME with hostname $HOSTNAME" >> /home/jelastic/add-sftp-user-addon/script_output.log
|
echo "Script completed for user $USERNAME with hostname $HOSTNAME" >> /home/jelastic/add-sftp-user-addon/script_output.log
|
||||||
|
|
|
@ -11,13 +11,9 @@ settings:
|
||||||
inputType: text
|
inputType: text
|
||||||
name: root_directory
|
name: root_directory
|
||||||
caption: 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."
|
description: "A user-specific directory will be created under this path."
|
||||||
required: false
|
required: false
|
||||||
- type: checkbox
|
|
||||||
name: agree_creation
|
|
||||||
caption: I agree to the creation of a folder and SFTP account.
|
|
||||||
required: true
|
|
||||||
- type: checkbox
|
- type: checkbox
|
||||||
name: enable_ssh
|
name: enable_ssh
|
||||||
caption: Also enable SSH access
|
caption: Also enable SSH access
|
||||||
|
|
Loading…
Reference in New Issue