Skip to content

Instantly share code, notes, and snippets.

@casesolved-co-uk
Created August 25, 2024 22:41
Show Gist options
  • Save casesolved-co-uk/6bb0d216e63e8bc292e156902c78217a to your computer and use it in GitHub Desktop.
Save casesolved-co-uk/6bb0d216e63e8bc292e156902c78217a to your computer and use it in GitHub Desktop.
Shell file for creating git server - restricts ssh commands to git only (probably not totally secure)
#!/bin/bash
# To force particular keys to only use git, prefix their entry on authorized_keys with:
# command="/home/user/ssh-git.sh" ssh-ed25519 AAAAC3NzaC....
# Only allows git commands
if [ -z "$SSH_ORIGINAL_COMMAND" ] || [ "$SSH_ORIGINAL_COMMAND" = "${SSH_ORIGINAL_COMMAND#git-}" ]; then
echo "Sorry, only git allowed"
else
client_arr=( ${SSH_CLIENT} )
client_ip=${client_arr[0]}
resolve_arr=( $(dig +noall +answer -x ${client_ip}) )
if [ -z "$resolve_arr" ]; then
client_host=""
else
client_host=" [${resolve_arr[-1]}]"
fi
echo "$(date -Iseconds) ${SSH_ORIGINAL_COMMAND} (${SSH_CLIENT})${client_host}" >> ssh-git.log
eval "$SSH_ORIGINAL_COMMAND"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment