Skip to content

Instantly share code, notes, and snippets.

@vglebov
Created December 6, 2016 05:36
Show Gist options
  • Select an option

  • Save vglebov/4b7f15d6be9117b5cddeeef7d457fc60 to your computer and use it in GitHub Desktop.

Select an option

Save vglebov/4b7f15d6be9117b5cddeeef7d457fc60 to your computer and use it in GitHub Desktop.
ConfigureAccessFromUserGit () {
if ! getent passwd git >/dev/null 2>&1; then
adduser git
su - -s /bin/bash git <<SU
mkdir .ssh
chmod 700 .ssh
touch .ssh/authorized_keys
chmod 600 .ssh/authorized_keys
SU
git_shell=$(which git-shell)
set +e
if ! grep ${git_shell} /etc/shells >/dev/null ; then
echo ${git_shell} >> /etc/shells
fi
set -e
chsh -s ${git_shell} git
su - -s /bin/bash git <<SU
mkdir git-shell-commands
touch git-shell-commands/no-interactive-login
SU
cat >/home/git/git-shell-commands/no-interactive-login <<'EOF'
#!/bin/sh
printf '%s\n' "Hi $USER! You've successfully authenticated, but I do not"
printf '%s\n' "provide interactive shell access."
exit 128
EOF
chmod +x /home/git/git-shell-commands/no-interactive-login
fi
}
CreateReposDir () {
repos_dir=$1
if [ ! -d "${repos_dir}" ]; then
mkdir -p ${repos_dir}
chown git:git ${repos_dir}
fi
}
ConfigureAccessFromUserGit
CreateReposDir /opt/git-repos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment