When you need a quick, offline Git repository for a small team or for personal projects, a full‑blown server can feel overkill. An Android phone or tablet that you already carry around can act as a lightweight Git server – no rooting, no extra hardware, just Termux. This tutorial walks you through every step, from installing the required packages to keeping the SSH daemon alive across reboots.
pkg update && pkg upgrade -y
This ensures you have the newest OpenSSH and Git builds.termux-setup-storage
Accept the Android dialog that appears.Why this matters: Updating packages prevents compatibility problems with newer Android security patches, and storage permission lets you place your repositories on a location with more space than the default Termux home directory.
pkg install git openssh -y
git provides the version‑control engine, while openssh supplies the sshd daemon for remote access.git --version
sshd -V
You should see version strings without errors.Both packages are compiled for the ARM64 (or x86) architecture used by most phones, so no extra configuration is needed.
ssh-keygen -t ed25519 -f ~/.ssh/git_key -N ""
-t ed25519 creates a modern, compact key.-f ~/.ssh/git_key stores the private key in ~/.ssh.-N "" leaves the passphrase empty – you can add one later for extra security.chmod 600 ~/.ssh/git_key
chmod 644 ~/.ssh/git_key.pubcat ~/.ssh/git_key.pubUsing a dedicated key isolates the Git server from your personal SSH keys, reducing the impact if the key is ever compromised.
sshd_config file that limits access to the Git user only:
cat > $HOME/sshd_config <<'EOF'
Port 2222
ListenAddress 0.0.0.0
PasswordAuthentication no
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
Subsystem sftp /system/bin/sh -c "echo 'SFTP disabled'; exit 1"
EOF
2222 is chosen to avoid the default 22 which may be blocked by some routers.cat ~/.ssh/git_key.pub >> ~/.ssh/authorized_keyssshd -f $HOME/sshd_config -D -e
The -D flag runs it in the foreground, and -e sends logs to stderr, which you will see in the Termux window.
sshd: no hostkeys available – exiting., generate host keys:
ssh-keygen -A -f $HOME/.ssh
Running the daemon in the foreground lets you verify that the config is accepted before moving to a background service.
mkdir -p /storage/emulated/0/GitReposexample.git:
git init --bare /storage/emulated/0/GitRepos/example.git
Bare repos are the standard format for a central Git server.
chmod -R 775 /storage/emulated/0/GitReposStoring the repo on external storage makes it easy to back up via a USB connection or cloud sync later.
sshd running after you close TermuxAndroid may kill background processes when the screen turns off. Termux provides two helpers that can keep services alive:
termux-wake-lock – prevents the device from sleeping.termux-job-scheduler – can schedule a command to run at boot.pkg install termux-api termux-services -ysshd with the custom config:
cat > $HOME/start-git-ssh.sh <<'EOS'
#!/data/data/com.termux/files/usr/bin/sh
# Acquire a wake lock so the daemon stays alive
termux-wake-lock
# Start sshd in the background
sshd -f $HOME/sshd_config
EOS
chmod +x $HOME/start-git-ssh.shtermux-service install -n git-ssh -a start -p $HOME/start-git-ssh.sh
This creates a .service file under ~/.termux/boot. The service will be launched automatically when the device boots.
termux-service start git-ssh
Check the log:
logcat | grep sshd
You should see a line like sshd[12345]: Server listening on 0.0.0.0 port 2222.
If you prefer not to use the Termux service framework, you can add the start command to ~/.bashrc and enable termux-wake-lock manually each session.
Clients need to know the phone’s IP address. There are two reliable ways:
mDNS advertises the device name as android.local. From a Linux or macOS client you can ping android.local.
On a laptop (Linux/macOS/Windows with Git Bash) run:
# Replace 192.168.1.42 with your phone’s IP
git clone ssh://git@192.168.1.42:2222/storage/emulated/0/GitRepos/example.git
Explanation of the URL:
git is the user name – we’ll create a matching system user in the next optional step.192.168.1.42:2222 points to the phone’s IP and the custom SSH port.If you get Permission denied (publickey), double‑check that the client’s SSH key is the one you added to authorized_keys. You can copy the private key from the phone to the client (or generate a new one on the client and add its public part to the phone).
Once cloned, you can add a file, commit, and push:
cd example
echo "Hello from Android!" > hello.txt
git add hello.txt
git commit -m "Add hello file"
git push origin master
On a second device, run the same clone command; you should see the hello.txt file after a git pull.
Termux runs as a single Linux user, but you can simulate a separate Git account by using the git-shell restricted shell. This step is optional for personal use but adds a layer of isolation if multiple people will connect.
git-shell binary (it ships with the git package):
ln -s $(which git-shell) $HOME/git-shellsshd_config to force the git user into git-shell:
echo "Match User git" >> $HOME/sshd_config
echo " ForceCommand $HOME/git-shell" >> $HOME/sshd_configmkdir -p $HOME/git_home/.ssh
cp ~/.ssh/authorized_keys $HOME/git_home/.ssh/
chmod 700 $HOME/git_home/.ssh
chmod 600 $HOME/git_home/.ssh/authorized_keysClients now log in as git@IP and are automatically placed in a restricted environment that only allows Git commands.
sshd fails to startssh-keygen -A -f $HOME/.ssh as shown earlier.netstat -tuln | grep 2222. Change the Port line in sshd_config to an unused number.ssh -v -i /path/to/key git@IP -p 2222 to view detailed handshake logs.chmod 600 ~/.ssh/authorized_keys on the phone.sshd so it reloads the authorized_keys file.git init --bare), not a normal working copy..git directory.termux-wake-lock is active (run termux-wake-lock -s to see the status).AllowTcpForwarding no and PermitTunnel no in sshd_config to reduce attack surface.authorized_keys on the phone.By the end of this guide you should have a fully functional Git server running on an Android device, reachable from any computer on the same LAN. The setup uses only free, open‑source tools bundled in Termux and requires no root access, making it safe to try on a primary phone. Remember to keep the device plugged in during heavy use, protect your SSH keys, and adjust battery‑optimization settings so Android doesn’t silently stop the daemon.









