Working files

main
Anthony 2023-10-30 20:52:48 +08:00
parent 1184e6b0d0
commit d7622fd2ab
2 changed files with 33 additions and 18 deletions

View File

@ -4,7 +4,8 @@
USERNAME="user$(shuf -i 10000-99999 -n 1)"
PASSWORD=$(openssl rand -base64 12)
ROOT_DIRECTORY="/var/www/webroot/ROOT"
# Set the user's home directory within the ROOT directory
USER_HOME="/var/www/webroot/ROOT/$USERNAME"
# Check if user already exists
if id "$USERNAME" &>/dev/null; then
@ -12,8 +13,8 @@ if id "$USERNAME" &>/dev/null; then
exit 1
fi
# Create user
useradd -m -d $ROOT_DIRECTORY $USERNAME
# Create user with the specified home directory
useradd -m -d $USER_HOME $USERNAME
if [ $? -ne 0 ]; then
echo "Failed to create user $USERNAME."
exit 1
@ -23,9 +24,10 @@ echo "$USERNAME:$PASSWORD" | chpasswd
# Set user's group to both litespeed and root
usermod -aG litespeed,root $USERNAME
# Adjust permissions for the user to write to the ROOT_DIRECTORY
chown $USERNAME:root $ROOT_DIRECTORY
chmod 775 $ROOT_DIRECTORY
# Adjust permissions for the user to write to their home directory
mkdir -p $USER_HOME
chown $USERNAME:root $USER_HOME
chmod 775 $USER_HOME
# Get the hostname
# Get the hostname (if needed later in the script)
HOSTNAME=$(hostname -f)

View File

@ -1,6 +1,5 @@
type: update
name: Add SFTP User
user: root
targetNodes:
nodeGroup: cp
@ -14,6 +13,10 @@ settings:
caption: Root Directory
default: "/var/www/webroot/ROOT"
required: true
- type: checkbox
name: agree_creation
caption: I agree to the creation of a folder and SFTP account.
required: true
- type: checkbox
name: enable_ssh
caption: Also enable SSH access
@ -26,19 +29,29 @@ globals:
sftpPort: 22
onInstall:
- cmd[cp]: bash <(curl -s https://deploy-proxy.mightybox.io/addons/add-sftp-user/raw/branch/main/install_sftp.sh)
- api: environment.control.ApplyNodeGroupData
nodeGroup: cp
data:
restart: true
- cmd[cp]: mkdir -p /home/jelastic/add-sftp-user-addon/
- cmd[cp]: wget https://deploy-proxy.mightybox.io/addons/add-sftp-user/raw/branch/main/add-sftp.sh -O /home/jelastic/add-sftp-user-addon/add-sftp.sh
- cmd[cp]: chmod +x /home/jelastic/add-sftp-user-addon/*.sh
- cmd[cp]:
commands:
- echo -e "\nMatch User user*\nPasswordAuthentication yes" >> /etc/ssh/sshd_config
user: root
- cmd[cp]:
commands:
- chown root:root /var/www/webroot/ROOT
- chmod 755 /var/www/webroot/ROOT
user: root
- cmd[cp]:
commands:
- systemctl restart sshd
user: root
- return: installSuccess
onUninstall:
- cmd[cp]: rm -f ./add-sftp.sh
actions:
add_sftp_user:
- cmd[cp]: bash <(curl -s https://deploy-proxy.mightybox.io/addons/add-sftp-user/raw/branch/main/add-sftp.sh)
- cmd[cp]:
commands: bash /home/jelastic/add-sftp-user-addon/add-sftp.sh
user: root
- return: sftpSuccess
responses: