Progress:
TIER 3 · MODULE 53· Expert

git shell

Restricted shell for SSH-only Git accounts.

🎯 What & why

git shell is a restricted login shell that only speaks Git. Set it as the git user's login shell on a server so SSH keys can push/fetch but cannot get an interactive shell.

🧠 Mental model

Think of it as a tiny allow-list dispatcher: SSH hands it a command string, it accepts only git-upload-pack, git-receive-pack, git-upload-archive (plus anything you drop into git-shell-commands/), and rejects everything else.

🛠️ Synopsis

git-shell [-c <command>]

# /etc/passwd entry
git:x:1001:1001::/home/git:/usr/bin/git-shell

# ad-hoc allow-list
~git/git-shell-commands/<name>   # executable scripts callable by name
~git/git-shell-commands/no-interactive-login   # custom banner on bare ssh

🎚️ Switches & options

FlagWhat it does
-c <cmd>Run the given Git command string (this is what sshd passes in)
(no args)Interactive mode; runs scripts from git-shell-commands/ if present, else exits
git-shell-commands/helpOptional script listed when the user types help
git-shell-commands/no-interactive-loginIf present, controls the message shown for bare ssh logins
chsh -s /usr/bin/git-shell git⚠️ Activates the restriction for the git user — verify SSH still works first

💡 Use cases

🧪 Examples

Add to /etc/shells then assign
echo /usr/bin/git-shell | sudo tee -a /etc/shells && sudo chsh -s /usr/bin/git-shell git
What sshd actually invokes
git-shell -c 'git-upload-pack /srv/git/repo.git'
Drop in an allow-listed admin script
sudo install -m 755 mkrepo.sh ~git/git-shell-commands/mkrepo
Test from a client against 127.0.0.1
ssh git@127.0.0.1 mkrepo new-project

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.