Skip to content

Instantly share code, notes, and snippets.

@miend
Created September 17, 2012 21:53
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 miend/3740018 to your computer and use it in GitHub Desktop.
Save miend/3740018 to your computer and use it in GitHub Desktop.
Simple scriptlet for parsing incoming SSH commands to either reject if they don't match the desired value or else escalate (via SUDO) if they do match
#! /bin/bash
# Exits if command not rsync.
# Escalates to root via sudo if rsync.
case "$SSH_ORIGINAL_COMMAND" in
*\&*|*\|*|*\;*|*\>*|*\<*|*\!*)
exit 1
;;
/usr/bin/rsync\ --server\ --sender*)
sudo $SSH_ORIGINAL_COMMAND
;;
*)
exit 1
;;
esac
@miend
Copy link
Author

miend commented Sep 17, 2012

"The intention is for bare-metal rsync backups by non-root user SSH in a secure fashion (i.e.; keypair + IP restriction + command restriction). So backup.company.com can run rsync@whateverhost and pull down everything thusly. (This is for rsnapshot in my home env.)"

~ Logos01

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment