This is a WordPress thing, right? I was having the same problem, and I was blaming Apache as well but the solution I found was actually a WordPress setting.
See https://codex.wordpress.org/Editing_wp-config.php#Override_of_default_file_permissions
On my particular server WordPress was using its own file permission settings (and ignoring the SGID bit) the same way you were describing. I don't know what the rationale is but it seems intentional. The solution for me was to add the specific permission mask to the wp-config.php file:
define( 'FS_CHMOD_DIR', 02775 );
With the existing WordPress files and directories set with the correct permission (including SGID on all directories), new files and directories created by WordPress (plugins, themes, uploads) used the 02755 file mask and inherited the correct group ownership. NOTE the Apache user www-data has to be in the group as well.
More details:
created group to be used by all SFTP users and Apache: sudo groupadd sftp-grp.
add Apache to group sftp-grp: sudo usermod -a -G sftp-grp www-data
add regular users to group sftp-grp, as above.
set all WordPress files to be owned by Apache, but with the shared group: sudo chown -R www-data:sftp-grp /var/www/path-to-wordpress
make sure all WordPress files are group read/writable (may want to re-consider for .htaccess and wp-config.php): sudo chmod -R g+rw /var/www/path-to-wordpress
add the SGID bit to the main WordPress directory: sudo chmod g+s /var/www/path-to-wordpress
... and all subdirectories: sudo find /var/www/path-to-wordpress -type d -exec chmod g+s '{}' \;
added to wp-config.php: define( 'FS_CHMOD_DIR', 02775 );
umask
of that process set to block the SGID bit? Is that program perhaps passing a mask to themkdir
call?