File tree Expand file tree Collapse file tree 8 files changed +98
-23
lines changed
Expand file tree Collapse file tree 8 files changed +98
-23
lines changed Original file line number Diff line number Diff line change 4545
4646# Enabling jailed sftp
4747if [ -z " $sftp_i " ]; then
48- echo " " >> $config
49- echo " # Hestia SFTP Chroot" >> $config
50- echo " Match User sftp_dummy99" >> $config
51- echo " ChrootDirectory %h " >> $config
52- echo " X11Forwarding no" >> $config
53- echo " AllowTCPForwarding no" >> $config
54- echo " ForceCommand internal-sftp" >> $config
55- restart=' yes'
48+ echo " " >> $config
49+ echo " # Hestia SFTP Chroot" >> $config
50+ echo " Match User sftp_dummy99" >> $config
51+ echo " ChrootDirectory /srv/jail/%u " >> $config
52+ echo " X11Forwarding no" >> $config
53+ echo " AllowTCPForwarding no" >> $config
54+ echo " ForceCommand internal-sftp -d /home " >> $config
55+ restart=' yes'
5656fi
5757
5858# Validating opensshd config
@@ -63,10 +63,10 @@ if [ "$restart" = 'yes' ]; then
6363 if [ " $? " -ne 0 ]; then
6464 mail_text=" OpenSSH can not be restarted. Please check config:
6565 \n\n$( /usr/sbin/sshd -t) "
66- echo -e " $mail_text " | $SENDMAIL -s " $subj " $email
67- else
68- service ssh restart > /dev/null 2>&1
69- fi
66+ echo -e " $mail_text " | $SENDMAIL -s " $subj " $email
67+ else
68+ service sshd restart > /dev/null 2>&1
69+ fi
7070fi
7171
7272# Checking users
Original file line number Diff line number Diff line change @@ -75,6 +75,7 @@ sed -i "s/$ssh_users/$users/g" /etc/ssh/sshd_config
7575if [ -d " /home/$user " ]; then
7676 chown root:root /home/$user
7777fi
78+ add_chroot_jail " $user "
7879
7980# ----------------------------------------------------------#
8081# Hestia #
@@ -85,7 +86,7 @@ if [ "$restart" = 'no' ]; then
8586 # Skip restart of SSH daemon
8687 echo " " > /dev/null 2>&1
8788else
88- service ssh restart > /dev/null 2>&1
89+ service sshd restart > /dev/null 2>&1
8990fi
9091
9192# Logging
Original file line number Diff line number Diff line change @@ -76,6 +76,10 @@ str=$(echo "$pw_str" | cut -f 1 -d :)
7676old_path=$( echo " $pw_str " | cut -f 7 -d :)
7777sed -i " $str s%$old_path %$ftp_path_a %g" /etc/passwd
7878
79+ # Updating chroot jail for SFTP and FTP
80+ delete_chroot_jail $ftp_user
81+ add_chroot_jail $ftp_user
82+
7983# ----------------------------------------------------------#
8084# Hestia #
8185# ----------------------------------------------------------#
Original file line number Diff line number Diff line change @@ -34,9 +34,8 @@ config='/etc/ssh/sshd_config'
3434sftp_n=$( grep -n " Subsystem.*sftp" $config | grep -v internal | grep " :#" )
3535sftp_i=$( grep -n " ^# Hestia SFTP Chroot" $config )
3636
37- date=$( " date +%s" )
3837# Backing up config
39- cp $config $config .bak- $( date +%s )
38+ cp $config $config .bak
4039
4140# Enabling normal sftp
4241if [ -n " $sftp_n " ]; then
@@ -61,9 +60,8 @@ if [ "$restart" = 'yes' ]; then
6160 if [ " $? " -ne 0 ]; then
6261 mail_text=" OpenSSH can not be restarted. Please check config:
6362 \n\n$( /usr/sbin/sshd -t) "
64- echo -e " $mail_text " | $SENDMAIL -s " $subj " " $email "
63+ echo -e " $mail_text " | $SENDMAIL -s " $subj " $email
6564 else
66- service ssh restart > /dev/null 2>&1
6765 service sshd restart > /dev/null 2>&1
6866 fi
6967fi
7775# Hestia #
7876# ----------------------------------------------------------#
7977
80- # Restart ssh service
81- service ssh restart > /dev/null 2>&1
82- service sshd restart > /dev/null 2>&1
83-
8478# Logging
8579$BIN /v-log-action " system" " Warning" " Plugins" " SFTP Chroot Jail disabled."
8680log_event " $OK " " $ARGUMENTS "
Original file line number Diff line number Diff line change @@ -68,12 +68,14 @@ sed -i "s/$ssh_users/$users/g" /etc/ssh/sshd_config
6868if [ -d " /home/$user " ]; then
6969 chown $user :$user /home/$user
7070fi
71+
72+ # Deleting chroot jail for SFTP and FTP
73+ delete_chroot_jail $user
7174# ----------------------------------------------------------#
7275# Hestia #
7376# ----------------------------------------------------------#
7477
7578# Restart ssh service
76- service ssh restart > /dev/null 2>&1
7779service sshd restart > /dev/null 2>&1
7880
7981# Logging
Original file line number Diff line number Diff line change @@ -1708,3 +1708,47 @@ search_command_arg_position() {
17081708
17091709 echo " $position "
17101710}
1711+
1712+ add_chroot_jail () {
1713+ local user=$1
1714+
1715+ mkdir -p /srv/jail/$user
1716+ chown 0:0 /srv /srv/jail /srv/jail/$user
1717+ chmod 755 /srv /srv/jail /srv/jail/$user
1718+ if [ ! -d /srv/jail/$user /home ]; then
1719+ mkdir -p /srv/jail/$user /home
1720+ chown 0:0 /srv/jail/$user /home
1721+ chmod 755 /srv/jail/$user /home
1722+ fi
1723+
1724+ cat > /etc/systemd/system/srv-jail-$user -home.mount << EOF
1725+ [Unit]
1726+ Description=Mount $user 's home directory to the jail chroot
1727+ Before=local-fs.target
1728+
1729+ [Mount]
1730+ What=$( getent passwd $user | cut -d : -f 6)
1731+ Where=/srv/jail/$user /home
1732+ Type=none
1733+ Options=bind
1734+ LazyUnmount=yes
1735+
1736+ [Install]
1737+ RequiredBy=local-fs.target
1738+ EOF
1739+
1740+ systemctl daemon-reload > /dev/null 2>&1
1741+ systemctl enable srv-jail-$user -home.mount > /dev/null 2>&1
1742+ systemctl start srv-jail-$user -home.mount > /dev/null 2>&1
1743+ }
1744+
1745+ delete_chroot_jail () {
1746+ local user=$1
1747+
1748+ systemctl stop srv-jail-$user -home.mount > /dev/null 2>&1
1749+ systemctl disable srv-jail-$user -home.mount > /dev/null 2>&1
1750+ rm -f /etc/systemd/system/srv-jail-$user -home.mount
1751+ systemctl daemon-reload > /dev/null 2>&1
1752+ rmdir /srv/jail/$user /home > /dev/null 2>&1
1753+ rmdir /srv/jail/$user > /dev/null 2>&1
1754+ }
Original file line number Diff line number Diff line change @@ -18,7 +18,9 @@ tcp_wrappers=YES
1818force_dot_files=YES
1919ascii_upload_enable=YES
2020ascii_download_enable=YES
21- allow_writeable_chroot=YES
21+ allow_writeable_chroot=NO
22+ local_root=/srv/jail/%u
23+ user_sub_token=%u
2224seccomp_sandbox=NO
2325pasv_enable=YES
2426pasv_promiscuous=YES
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ # Hestia Control Panel upgrade script for target version 1.9.0
4+
5+ # ######################################################################################
6+ # ###### Place additional commands below. #######
7+ # ######################################################################################
8+ # ###### upgrade_config_set_value only accepts true or false. #######
9+ # ###### #######
10+ # ###### Pass through information to the end user in case of a issue or problem #######
11+ # ###### #######
12+ # ###### Use add_upgrade_message "My message here" to include a message #######
13+ # ###### in the upgrade notification email. Example: #######
14+ # ###### #######
15+ # ###### add_upgrade_message "My message here" #######
16+ # ###### #######
17+ # ###### You can use \n within the string to create new lines. #######
18+ # ######################################################################################
19+
20+ upgrade_config_set_value ' UPGRADE_UPDATE_WEB_TEMPLATES' ' false'
21+ upgrade_config_set_value ' UPGRADE_UPDATE_DNS_TEMPLATES' ' false'
22+ upgrade_config_set_value ' UPGRADE_UPDATE_MAIL_TEMPLATES' ' false'
23+ upgrade_config_set_value ' UPGRADE_REBUILD_USERS' ' yes'
24+ upgrade_config_set_value ' UPGRADE_UPDATE_FILEMANAGER_CONFIG' ' false'
25+
26+ # update config sftp jail
27+ $BIN /v-delete-sys-sftp-jail
28+ $BIN /v-add-sys-sftp-jail
You can’t perform that action at this time.
0 commit comments