Created
August 25, 2024 22:41
-
-
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)
This file contains 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 | |
# 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