Last active
April 2, 2018 15:11
-
-
Save sdovnic/8bd403526944c24fc2006333b91a0dc1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Copyright 2018 - 2018 | |
groups=$(cat /var/lib/extrausers/group | awk -F ':' '{print $1}') | |
hash=$(md5sum /etc/ssh/sshd_config) | |
echo "" > /tmp/sshd_froxlor | |
for group in ${groups}; do | |
echo "Match Group ${group}" >> /tmp/sshd_froxlor | |
echo " ChrootDirectory /var/customers/sftp/${group}" >> /tmp/sshd_froxlor | |
echo " ForceCommand internal-sftp" >> /tmp/sshd_froxlor | |
echo " AllowTCPForwarding no" >> /tmp/sshd_froxlor | |
echo " X11Forwarding no\n" >> /tmp/sshd_froxlor | |
if [ ! -d /var/customers/sftp/${group}/webs ]; then | |
mkdir -p /var/customers/sftp/${group}/webs | |
fi | |
if [ ! -n "$(mount | grep /var/customers/sftp/${group}/webs)" ]; then | |
mount --bind /var/customers/webs/${group} /var/customers/sftp/${group}/webs | |
fi | |
done | |
lead='^### BEGIN FROXLOR$' | |
tail='^### END FROXLOR$' | |
sed -i "/$lead/,/$tail/{ /$lead/{p; r /tmp/sshd_froxlor | |
}; /$tail/p; d }" /etc/ssh/sshd_config | |
if [ -f /tmp/sshd_froxlor ]; then | |
rm /tmp/sshd_froxlor | |
fi | |
if [ "${hash}" != "$(md5sum /etc/ssh/sshd_config)" ]; then | |
/etc/init.d/ssh restart | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment