Skip to content

Instantly share code, notes, and snippets.

@afresh1
Created August 25, 2021 15:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afresh1/16929acd675e25ff559c01f71dc26a11 to your computer and use it in GitHub Desktop.
Save afresh1/16929acd675e25ff559c01f71dc26a11 to your computer and use it in GitHub Desktop.
A script to use as an SSH ForceCommand that only lets root connect to run rsync in the way FreeNAS/TrueNAS does it.
#!/bin/sh
expect='rsync --server --sender -logDtprze.LsfxC . /'
dir="/${SSH_ORIGINAL_COMMAND#$expect}"
# Try without compression
if [ "$dir" = "/${SSH_ORIGINAL_COMMAND}" ]; then
expect='rsync --server --sender -logDtpre.LsfxC . /'
dir="/${SSH_ORIGINAL_COMMAND#$expect}"
fi
if [ "$dir" != "/${SSH_ORIGINAL_COMMAND}" -a -e "$dir" ]; then
exec ${SSH_ORIGINAL_COMMAND} -vvv
fi
set -- ${SSH_CONNECTION}
SRC="$1 port $2"
DST="$3 port $4"
logger -t force_rsync -p auth.warning \
"Invalid rsync command from user ${USER} ${SRC}: [${SSH_ORIGINAL_COMMAND}]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment