Created
November 9, 2016 10:34
-
-
Save stemid/abbc96e5b3cac83b0985557bb91d15a0 to your computer and use it in GitHub Desktop.
Script for this guide https://wiki.sydit.se/teknik:guider:chrootad_sftp_med_pam_mysql_pa_rhel6
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 | |
home_base=/var/sftp | |
test $(id -u $PAM_USER) -gt 500 || exit 1 | |
grep ^{{chroot_openssh_group}} /etc/group | grep -q $PAM_USER || exit 1 | |
_HOME=$(getent passwd $PAM_USER 2>/dev/null | cut -d: -f6 2>/dev/null) | |
if [ -z "$_HOME" ]; then | |
_HOME="/home/$PAM_USER" | |
fi | |
test -d $_HOME || exit 1 | |
if [ ! -d "$home_base/$PAM_USER" ]; then | |
echo "Creating home $home_base/$PAM_USER" | |
mkdir -p "$home_base/$PAM_USER" | |
fi | |
if [ ! -d "$home_base/$PAM_USER/ftp_home" ]; then | |
echo "Creating ftp_home mount point for $PAM_USER" | |
mkdir "$home_base/$PAM_USER/ftp_home" | |
fi | |
if ! mount | grep "$home_base/$PAM_USER/ftp_home type none (rw,bind)" &>/dev/null; then | |
echo "Mounting ftp_home in users ($PAM_USER) sftp-dir " | |
mount -B "$_HOME" "$home_base/$PAM_USER/ftp_home" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment