Skip to content

Instantly share code, notes, and snippets.

@lmas
Created December 23, 2022 11:33
Show Gist options
  • Save lmas/22efff024858e21a615a3ca5d9854e2e to your computer and use it in GitHub Desktop.
Save lmas/22efff024858e21a615a3ca5d9854e2e to your computer and use it in GitHub Desktop.
Reject anything but rsync through ssh
#!/bin/sh
# Script to reject anything but rsync through ssh.
# Source: https://troy.jdmz.net/rsync/index.html
#
# To force run it on new ssh connections, add:
# command="/home/USER/force_rsync.sh"
# to /home/USER/.ssh/authorized_keys, at the start
# of the key line of enforced user.
case "$SSH_ORIGINAL_COMMAND" in
*\&*)
echo "Rejected"
;;
*\(*)
echo "Rejected"
;;
*\{*)
echo "Rejected"
;;
*\;*)
echo "Rejected"
;;
*\<*)
echo "Rejected"
;;
*\>*)
echo "Rejected"
;;
*\`*)
echo "Rejected"
;;
*\|*)
echo "Rejected"
;;
rsync\ --server*)
$SSH_ORIGINAL_COMMAND
;;
*)
echo "Rejected"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment