Compare commits
2 Commits
d7622fd2ab
...
5bb722a83d
Author | SHA1 | Date |
---|---|---|
|
5bb722a83d | |
|
f38ef098fa |
23
add-sftp.sh
23
add-sftp.sh
|
@ -1,33 +1,30 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Generate random username and password
|
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)
|
||||||
|
|
||||||
# Set the user's home directory within the ROOT directory
|
ROOT_DIRECTORY="/var/www/webroot/ROOT"
|
||||||
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
|
||||||
echo "User $USERNAME already exists."
|
echo "User $USERNAME already exists." >> /home/jelastic/add-sftp-user-addon/script_output.log
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create user with the specified home directory
|
# Create user
|
||||||
useradd -m -d $USER_HOME $USERNAME
|
useradd -m -d $ROOT_DIRECTORY $USERNAME
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Failed to create user $USERNAME."
|
echo "Failed to create user $USERNAME." >> /home/jelastic/add-sftp-user-addon/script_output.log
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
echo "$USERNAME:$PASSWORD" | chpasswd
|
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 their home directory
|
# Adjust permissions for the user to write to the ROOT_DIRECTORY
|
||||||
mkdir -p $USER_HOME
|
chown $USERNAME:root $ROOT_DIRECTORY
|
||||||
chown $USERNAME:root $USER_HOME
|
chmod 775 $ROOT_DIRECTORY
|
||||||
chmod 775 $USER_HOME
|
|
||||||
|
|
||||||
# Get the hostname (if needed later in the script)
|
|
||||||
HOSTNAME=$(hostname -f)
|
HOSTNAME=$(hostname -f)
|
||||||
|
echo "Script completed for user $USERNAME with hostname $HOSTNAME" >> /home/jelastic/add-sftp-user-addon/script_output.log
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Root User
|
|
||||||
sudo su
|
|
||||||
# Update sshd_config
|
|
||||||
echo -e "\nMatch User user*\nPasswordAuthentication yes" >> /etc/ssh/sshd_config
|
|
||||||
# Adjust permissions
|
|
||||||
chown root:root /var/www/webroot/ROOT
|
|
||||||
chmod 755 /var/www/webroot/ROOT
|
|
||||||
|
|
||||||
#Restart SSH daemon
|
|
||||||
sudo systemctl restart sshd
|
|
17
manifest.jps
17
manifest.jps
|
@ -45,6 +45,8 @@ onInstall:
|
||||||
commands:
|
commands:
|
||||||
- systemctl restart sshd
|
- systemctl restart sshd
|
||||||
user: root
|
user: root
|
||||||
|
- api: environment.control.RestartContainer
|
||||||
|
nodeGroup: cp
|
||||||
- return: installSuccess
|
- return: installSuccess
|
||||||
|
|
||||||
actions:
|
actions:
|
||||||
|
@ -52,12 +54,27 @@ actions:
|
||||||
- cmd[cp]:
|
- cmd[cp]:
|
||||||
commands: bash /home/jelastic/add-sftp-user-addon/add-sftp.sh
|
commands: bash /home/jelastic/add-sftp-user-addon/add-sftp.sh
|
||||||
user: root
|
user: root
|
||||||
|
- if ("${response.exitStatus}" != "0"):
|
||||||
|
return: sftpError
|
||||||
- return: sftpSuccess
|
- return: sftpSuccess
|
||||||
|
|
||||||
|
onUninstall:
|
||||||
|
- cmd[cp]:
|
||||||
|
commands:
|
||||||
|
- rm -rf /home/jelastic/add-sftp-user-addon/
|
||||||
|
user: root
|
||||||
|
- return: uninstallSuccess
|
||||||
|
|
||||||
responses:
|
responses:
|
||||||
|
uninstallSuccess:
|
||||||
|
type: success
|
||||||
|
message: "Uninstalled Successfully"
|
||||||
installSuccess:
|
installSuccess:
|
||||||
type: success
|
type: success
|
||||||
message: "Installed Successfully"
|
message: "Installed Successfully"
|
||||||
|
sftpError:
|
||||||
|
type: error
|
||||||
|
message: "Failed to add SFTP user. Please check the server logs for more details."
|
||||||
sftpSuccess:
|
sftpSuccess:
|
||||||
type: success
|
type: success
|
||||||
email: |-
|
email: |-
|
||||||
|
|
Loading…
Reference in New Issue