Chrooted SFTP access also for suEXEC (mod_fcgid) sites
create_vhost.sh: - suEXEC (mod_fcgid) sites get the same chrooted SFTP setup as static suEXEC sites: web base directory root:root 755, DocumentRoot owned by suEXEC user/group, SFTP group membership, sshd and chroot path checks. - SFTP group: use $SFTP_CHROOT_GROUP if it exists, otherwise 'sftpusers' (if exists). If neither exists, skip that step (group is no longer created). fix_sftp_site_permissions.sh: - Also handle active '*.suexec' vhosts. PHP files (*.php, *.phtml, *.php5) are not touched there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
76f0fe1a7a
commit
fec60403d1
3 files changed
+117
-47
No files matched your search
+62
-31
@@ -309,10 +309,15 @@ VHOST_DIR=""
|
||||
WEBSITES_ROOT_DIR=""
|
||||
CREATE_SYMLINK_WEB_BASE_DIR=false
|
||||
|
||||
# - Static site with suEXEC and chrooted SFTP access:
|
||||
# - suEXEC sites (suEXEC using mod_fcgid and static site with suEXEC)
|
||||
# - with chrooted SFTP access:
|
||||
# - sshd has to restrict members of that group to (chrooted) sftp
|
||||
# -
|
||||
# - If this group does not exist, group 'sftpusers' is used (if exists).
|
||||
# - If neither exists, the suEXEC user is not added to any SFTP group.
|
||||
# -
|
||||
SFTP_CHROOT_GROUP="sftp-chroot"
|
||||
SFTP_CHROOT_GROUP_FALLBACK="sftpusers"
|
||||
|
||||
|
||||
# ---
|
||||
@@ -487,7 +492,7 @@ if [ "$_type" != "PHP-FPM" -a "$_type" != "FCGID" -a "$_type" != "MOD_PHP" -a "$
|
||||
echo "[1] PHP-FPM (FastCGI Process Manager)"
|
||||
echo "[2] mod_fcgid (Apache FastCGI implementation)"
|
||||
echo "[3] mod_php (Apache PHP Module)"
|
||||
echo "[4] suEXEC (using mod_fcgid)"
|
||||
echo "[4] suEXEC (using mod_fcgid, chrooted SFTP access)"
|
||||
echo "[5] static site (No PHP engine enabled)"
|
||||
echo "[6] only redirect"
|
||||
echo "[7] parke domain/site"
|
||||
@@ -574,6 +579,26 @@ else
|
||||
echo "Configure site \"${site_url}\" - \"$_type_msg\""
|
||||
fi
|
||||
|
||||
# - All suEXEC sites ([4] suEXEC using mod_fcgid and [8] static site with suEXEC)
|
||||
# - get chrooted SFTP access: the suEXEC user is the (chrooted) SFTP user.
|
||||
# -
|
||||
if $_suEXEC ; then
|
||||
_sftp_chroot=true
|
||||
fi
|
||||
|
||||
# - Determine the SFTP group the suEXEC user will be added to:
|
||||
# - $SFTP_CHROOT_GROUP, if it exists, otherwise $SFTP_CHROOT_GROUP_FALLBACK
|
||||
# - ('sftpusers'), if it exists. If neither exists, no SFTP group is used.
|
||||
# -
|
||||
_sftp_group=""
|
||||
if $_sftp_chroot ; then
|
||||
if [[ -n "$SFTP_CHROOT_GROUP" ]] && getent group "$SFTP_CHROOT_GROUP" > /dev/null ; then
|
||||
_sftp_group="$SFTP_CHROOT_GROUP"
|
||||
elif [[ -n "$SFTP_CHROOT_GROUP_FALLBACK" ]] && getent group "$SFTP_CHROOT_GROUP_FALLBACK" > /dev/null ; then
|
||||
_sftp_group="$SFTP_CHROOT_GROUP_FALLBACK"
|
||||
fi
|
||||
fi
|
||||
|
||||
if $_base_webserver_info_needed ; then
|
||||
|
||||
|
||||
@@ -2079,7 +2104,11 @@ if $_print_summary ; then
|
||||
fi
|
||||
if $_sftp_chroot ; then
|
||||
echo " SFTP chroot directory (home)...: $_web_base_dir"
|
||||
echo " SFTP chroot group (sshd).......: $SFTP_CHROOT_GROUP"
|
||||
if [[ -n "$_sftp_group" ]]; then
|
||||
echo " SFTP chroot group (sshd).......: $_sftp_group"
|
||||
else
|
||||
echo -e " SFTP chroot group (sshd).......: \033[33mnone\033[m (neither \"$SFTP_CHROOT_GROUP\" nor \"$SFTP_CHROOT_GROUP_FALLBACK\" exists)"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo ""
|
||||
@@ -2447,32 +2476,24 @@ if $_suEXEC ; then
|
||||
|
||||
if $_sftp_chroot ; then
|
||||
|
||||
echononl "\tAdding Group \"$SFTP_CHROOT_GROUP\" (chrooted SFTP users).."
|
||||
if getent group $SFTP_CHROOT_GROUP > /dev/null ; then
|
||||
echo_skipped
|
||||
else
|
||||
groupadd $SFTP_CHROOT_GROUP
|
||||
if [ "$?" = "0" ]; then
|
||||
echo_ok
|
||||
if [[ -n "$_sftp_group" ]]; then
|
||||
echononl "\tAdd user \"$suEXEC_user\" to group \"$_sftp_group\" (chrooted SFTP users).."
|
||||
if id -nG $suEXEC_user | tr ' ' '\n' | grep -q -x "$_sftp_group" ; then
|
||||
echo_skipped
|
||||
else
|
||||
echo_failed
|
||||
error "Cannot create Group \"$SFTP_CHROOT_GROUP\"."
|
||||
fatal
|
||||
usermod -a -G $_sftp_group $suEXEC_user
|
||||
if [ "$?" = "0" ]; then
|
||||
echo_ok
|
||||
else
|
||||
echo_failed
|
||||
error "Cannot add user \"$suEXEC_user\" to group \"$_sftp_group\"."
|
||||
fatal
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
echononl "\tAdd user \"$suEXEC_user\" to group \"$SFTP_CHROOT_GROUP\".."
|
||||
if id -nG $suEXEC_user | tr ' ' '\n' | grep -q -x "$SFTP_CHROOT_GROUP" ; then
|
||||
echo_skipped
|
||||
else
|
||||
usermod -a -G $SFTP_CHROOT_GROUP $suEXEC_user
|
||||
if [ "$?" = "0" ]; then
|
||||
echo_ok
|
||||
else
|
||||
echo_failed
|
||||
error "Cannot add user \"$suEXEC_user\" to group \"$SFTP_CHROOT_GROUP\"."
|
||||
fatal
|
||||
fi
|
||||
echononl "\tAdd user \"$suEXEC_user\" to a SFTP group (\"$SFTP_CHROOT_GROUP\" / \"$SFTP_CHROOT_GROUP_FALLBACK\").."
|
||||
echo_skipped
|
||||
warn "Neither group \"$SFTP_CHROOT_GROUP\" nor group \"$SFTP_CHROOT_GROUP_FALLBACK\" exists.\n\t User \"$suEXEC_user\" was NOT added to a SFTP group."
|
||||
fi
|
||||
|
||||
# - Webserver user must be able to read all files of the SFTP user
|
||||
@@ -2581,10 +2602,16 @@ else
|
||||
fi
|
||||
|
||||
echononl "\tChange owner of Web Base directory \"$_web_base_dir\".."
|
||||
if $_sftp_chroot ; then
|
||||
if $_suEXEC ; then
|
||||
|
||||
# - suEXEC sites (suEXEC using mod_fcgid and static site with suEXEC):
|
||||
# -
|
||||
# - The web base directory is the home directory of the suEXEC user and
|
||||
# - serves as SFTP chroot directory.
|
||||
# -
|
||||
# - SFTP chroot (sshd): The chroot directory and all its parent directories
|
||||
# - must be owned by root and must not be writable by group or others.
|
||||
# - The subdirectories (DocumentRoot, conf, ..) are owned by the suEXEC user.
|
||||
# -
|
||||
# - Note: also done, if the directory already exists - otherwise sshd
|
||||
# - refuses the (chrooted) login.
|
||||
@@ -2620,9 +2647,7 @@ if $_sftp_chroot ; then
|
||||
elif $web_base_directory_already_exists ; then
|
||||
echo_skipped
|
||||
else
|
||||
if $_suEXEC ; then
|
||||
chown -R ${suEXEC_user}:$suEXEC_group $_web_base_dir
|
||||
elif [[ "$_type" = "PHP-FPM" ]]; then
|
||||
if [[ "$_type" = "PHP-FPM" ]]; then
|
||||
chown -R ${unix_socket_owner}:${unix_socket_group} $_web_base_dir
|
||||
else
|
||||
chown -R ${web_user}:${web_group} $_web_base_dir
|
||||
@@ -3702,7 +3727,7 @@ if $_sftp_chroot && $_sshd_chroot_missing ; then
|
||||
\t (Match blocks in files included at the top of sshd_config, i.e.
|
||||
\t /etc/ssh/sshd_config.d/*.conf, may affect the following settings):
|
||||
|
||||
\t \033[1mMatch Group ${SFTP_CHROOT_GROUP}
|
||||
\t \033[1mMatch Group ${_sftp_group:-$SFTP_CHROOT_GROUP}
|
||||
\t ChrootDirectory %h
|
||||
\t ForceCommand internal-sftp -u 0027
|
||||
\t AllowTcpForwarding no
|
||||
@@ -3718,6 +3743,12 @@ if $_sftp_chroot && $_sshd_chroot_missing ; then
|
||||
\t sshd -T -C user=${suEXEC_user},host=localhost,addr=127.0.0.1 | grep -i -E '^(chrootdirectory|forcecommand)'
|
||||
|
||||
\t Note: 'AllowUsers'/'AllowGroups' (if used) must permit the user."
|
||||
if [[ -z "$_sftp_group" ]]; then
|
||||
warn "User \"$suEXEC_user\" is not member of a SFTP group. Create group and add user:
|
||||
|
||||
\t groupadd $SFTP_CHROOT_GROUP
|
||||
\t usermod -a -G $SFTP_CHROOT_GROUP $suEXEC_user"
|
||||
fi
|
||||
fi
|
||||
|
||||
if $_sftp_chroot && ! grep -q -r 'fix_sftp_site_permissions' /etc/cron.d /etc/crontab /var/spool/cron 2> /dev/null ; then
|
||||
|
||||
Reference in new issue
Block a user