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

View File

@ -1,6 +1,5 @@
type: update type: update
name: Add SFTP User name: Add SFTP User
user: root
targetNodes: targetNodes:
nodeGroup: cp nodeGroup: cp
@ -14,6 +13,10 @@ settings:
caption: Root Directory caption: Root Directory
default: "/var/www/webroot/ROOT" default: "/var/www/webroot/ROOT"
required: true required: true
- 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
@ -26,19 +29,29 @@ globals:
sftpPort: 22 sftpPort: 22
onInstall: onInstall:
- cmd[cp]: bash <(curl -s https://deploy-proxy.mightybox.io/addons/add-sftp-user/raw/branch/main/install_sftp.sh) - cmd[cp]: mkdir -p /home/jelastic/add-sftp-user-addon/
- api: environment.control.ApplyNodeGroupData - 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
nodeGroup: cp - cmd[cp]: chmod +x /home/jelastic/add-sftp-user-addon/*.sh
data: - cmd[cp]:
restart: true 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 - return: installSuccess
onUninstall:
- cmd[cp]: rm -f ./add-sftp.sh
actions: actions:
add_sftp_user: 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 - return: sftpSuccess
responses: responses: