Skip to content

Instantly share code, notes, and snippets.

@stemid
Created November 9, 2016 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stemid/abbc96e5b3cac83b0985557bb91d15a0 to your computer and use it in GitHub Desktop.
Save stemid/abbc96e5b3cac83b0985557bb91d15a0 to your computer and use it in GitHub Desktop.
#!/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