Created
July 31, 2025 04:26
-
-
Save rohityadavcloud/ca3a4c8a727a8480a7a5f2f1c23591bf to your computer and use it in GitHub Desktop.
check-ssh: limit what is allowed via ssh
This file contains hidden or 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
#!/bin/bash | |
# only rsync allowed via ssh | |
# add the following in the users's ~/.ssh/authorised_keys: | |
# command="/root/checkssh.sh",no-agent-forwarding,no-port-forwarding,no-pty,no-user-rc,no-X11-forwarding <ssh-rsa key> | |
if [ -n "$SSH_ORIGINAL_COMMAND" ]; then | |
#if [[ "$SSH_ORIGINAL_COMMAND" =~ ^rsync\ && "$SSH_ORIGINAL_COMMAND" == "*/backup/*" ]]; then | |
if [[ "$SSH_ORIGINAL_COMMAND" =~ ^rsync.*backup.* ]]; then | |
echo "`/bin/date`: $SSH_ORIGINAL_COMMAND" >> $HOME/rsync-ssh.log | |
exec $SSH_ORIGINAL_COMMAND | |
else | |
echo "`/bin/date`: DENIED $SSH_ORIGINAL_COMMAND" >> $HOME/rsync-ssh.log | |
echo "Access denied for command '$SSH_ORIGINAL_COMMAND'; only rsync to /backup allowed" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment