Run a Local Git Server on Android Using Termux (No Root)

16 min read Learn how to turn an Android device into a lightweight Git server with Termux, without rooting. Step‑by‑step setup, SSH keys, and troubleshooting. October 11, 2026 19:30 How to Run a Local Git Server on Android Using Termux (No Root)

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.

Before you start

  • Device requirements: Android 8.0 (Oreo) or newer. Older versions may lack the required OpenSSH binaries.
  • Network: The phone should stay on a stable Wi‑Fi network. Using a dedicated SSID for the server helps avoid accidental exposure.
  • Power: Keep the device plugged in or ensure at least 80 % battery. Android may kill background processes when battery is low.
  • Backup: The steps create a new user directory inside Termux. It won’t touch your personal data, but it’s good practice to have a recent backup of any important files.
  • Permissions: You will need to grant Termux access to device storage (Storage permission) so that the repository can be stored on internal or external storage.
If you plan to use the Git server from another Android device, make sure both devices are on the same Wi‑Fi subnet.

Step 1 – Install Termux and update the environment

  1. Open the F‑Droid page for Termux and install the latest version. (Google Play no longer receives updates.)
  2. Launch Termux. The first launch will set up the basic environment.
  3. Update package lists and upgrade existing packages:
    pkg update && pkg upgrade -y
    This ensures you have the newest OpenSSH and Git builds.
  4. Grant storage permission so Termux can read/write external storage:
    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.

Step 2 – Install Git and OpenSSH

  1. Install the core tools:
    pkg install git openssh -y
    git provides the version‑control engine, while openssh supplies the sshd daemon for remote access.
  2. Verify the installations:
    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.

Step 3 – Create a dedicated SSH key pair

  1. Generate a new SSH key that will be used by clients to authenticate:
    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.
  2. Set proper permissions (SSH will refuse keys that are too open):
    chmod 600 ~/.ssh/git_key
    chmod 644 ~/.ssh/git_key.pub
  3. Display the public key so you can copy it to client machines:
    cat ~/.ssh/git_key.pub

Using a dedicated key isolates the Git server from your personal SSH keys, reducing the impact if the key is ever compromised.

Step 4 – Configure the SSH daemon

  1. Create an 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
    • Port 2222 is chosen to avoid the default 22 which may be blocked by some routers.
    • Disabling password authentication forces the use of the key generated above.
    • We also disable SFTP because the server’s purpose is Git over SSH, not file transfer.
  2. Append the public key to the list of authorized keys:
    cat ~/.ssh/git_key.pub >> ~/.ssh/authorized_keys
  3. Start the daemon manually to test the configuration:
    sshd -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.
    • If you see 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.

Step 5 – Create a bare repository for remote use

  1. Decide where you want the repositories to live. For this tutorial we’ll use a folder on external storage so it survives a Termux reinstall:
    mkdir -p /storage/emulated/0/GitRepos
  2. Initialize a bare repository (a repository without a working tree) named example.git:
    git init --bare /storage/emulated/0/GitRepos/example.git
    Bare repos are the standard format for a central Git server.
  3. Adjust permissions so the SSH daemon (running as your Termux user) can read/write the repo:
    chmod -R 775 /storage/emulated/0/GitRepos

Storing the repo on external storage makes it easy to back up via a USB connection or cloud sync later.

Step 6 – Keep sshd running after you close Termux

Android 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.
  1. Install the helper packages:
    pkg install termux-api termux-services -y
  2. Create a small script that starts sshd 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.sh
  3. Register the script as a Termux service that starts at boot:
    termux-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.
  4. Manually start the service now to verify it works:
    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.

Step 7 – Make the Android device reachable on your LAN

Clients need to know the phone’s IP address. There are two reliable ways:

  • Static IP: In your Wi‑Fi router’s DHCP settings, assign a fixed IP to the phone’s MAC address.
  • Hostname: Android’s mDNS advertises the device name as android.local. From a Linux or macOS client you can ping android.local.
If you cannot reach the device by name, use the IP shown in Settings → Network & Internet → Wi‑Fi → Advanced → IP address.

Step 8 – Clone, push, and pull from a client machine

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.
  • The path after the colon is the absolute location of the bare repository.

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.

Optional – Create a dedicated “git” system user

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.

  1. Add the git-shell binary (it ships with the git package):
    ln -s $(which git-shell) $HOME/git-shell
  2. Modify sshd_config to force the git user into git-shell:
    echo "Match User git" >> $HOME/sshd_config
    echo "    ForceCommand $HOME/git-shell" >> $HOME/sshd_config
  3. Create a home directory for the pseudo‑user and copy the authorized keys:
    mkdir -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_keys
  4. Restart the daemon (or stop/start the Termux service) so the new rules take effect.

Clients now log in as git@IP and are automatically placed in a restricted environment that only allows Git commands.

Troubleshooting

1. sshd fails to start

  • Missing host keys: Run ssh-keygen -A -f $HOME/.ssh as shown earlier.
  • Port already in use: Verify no other app occupies port 2222 with netstat -tuln | grep 2222. Change the Port line in sshd_config to an unused number.
  • SELinux or Android restrictions: Some OEM skins block background network listeners. Try disabling battery optimizations for Termux (Settings → Apps → Termux → Battery → Unrestricted).

2. Client cannot authenticate

  • Ensure the public key on the phone exactly matches the private key used by the client. Use ssh -v -i /path/to/key git@IP -p 2222 to view detailed handshake logs.
  • Check file permissions: chmod 600 ~/.ssh/authorized_keys on the phone.
  • If you added a new key, restart sshd so it reloads the authorized_keys file.

3. Repository appears empty after clone

  • Make sure you initialized a bare repository (git init --bare), not a normal working copy.
  • Verify the path in the clone URL points to the exact .git directory.

4. Android kills the SSH service after a screen timeout

  • Confirm termux-wake-lock is active (run termux-wake-lock -s to see the status).
  • Some manufacturers (e.g., Huawei, Xiaomi) have aggressive task‑kill policies. Add Termux to the “Protected apps” list or disable “Auto‑start manager” for Termux.

Security considerations

  • Use a strong, unique SSH key pair; never reuse keys from other servers.
  • Limit the server to trusted Wi‑Fi networks. If you need remote access over the internet, set up port forwarding on your router and use a firewall rule to allow only your public IP.
  • Consider enabling AllowTcpForwarding no and PermitTunnel no in sshd_config to reduce attack surface.
  • Regularly rotate the key by generating a new pair and updating authorized_keys on the phone.

Wrapping up

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.

User Comments (0)

Add Comment
We'll never share your email with anyone else.