Termux Git Host with Ubuntu Local Client

Prerequisites

Knowing these commands are issued in a Terminal on both Host and Local device is a must.

(Host) Termux Android terminal emulator.

(Local) A device capable of generating RSA key pairs with git installed.
Ubuntu users:
16.04
sudo update
sudo apt upgrade
sudo apt install git-core
18.04, 19.04
sudo apt update
sudo apt upgrade
sudo apt install git

Termux Installed

Add user password.
passwd

Install OpenSSH and Git
pkg update
pkg upgrade
pkg install openssh git

Create a new bare repository on the host device.
mkdir project.git
cd project.git
git init --bare

Start SSHD
sshd

Termux Tips

IP of this device.
ip -f inet address
For example my tablet connected to wifi would output something similar to this.

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
11: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    inet 192.168.0.00/24 brd 192.168.0.255 scope global wlan0
       valid_lft forever preferred_lft forever

I will SSH into the connected = termux_device_IP, the local IP address of the host device.

Kill SSHD
pkill sshd

Restart SSHD
pkill sshd; sshd

Ubuntu our Local Client

On your Ubuntu machine create a RSA public / private key..
ssh-keygen -t rsa -b 2048 -f id_rsa
This will leave you with two files in the directory you ran the command in, a public key called id_rsa.pub and a private key id_rsa without an extension. Do not ever hand out the private key or move it to the device you are attempting to authenticate with, for example do not move it to the Termux host device.

At this point we can authenticate via password with our Termux host running SSH. We will add our RSA public key for password-less authentication. You will have to first login at least once with the password you created in Termux.
ssh-copy-id -p8022 -i /path/to/file/id_rsa termux_device_IP

Add id_rsa to keychain
chmod 600 id_rsa
mv id_rsa ~/.ssh/
ssh-add ~/.ssh/id_rsa

SSH into the Termux host device.
ssh -p8022 termux_device_IP

Connected SSH Session - Termux Host

Install a text editor Nano | Vim whatever.
pkg install nano

Edit SSH config file
nano $PREFIX/etc/ssh/sshd_config
PasswordAuthentication no
Save the file
Restart SSHD
pkill sshd; sshd
The password prompt to login over ssh is now disabled, you will need your private key.

Git on Ubuntu


Create a new project
mkdir project
cd project
git init
git add .
git commit -m 'my commit'
git remote add origin ssh://termux_device_IP:8022/data/data/com.termux/files/home/project.git
git push origin master

Clone the repo
git clone ssh://termux_device_IP:8022/data/data/com.termux/files/home/project.git


Simple as that and you can use tools like qgit if you want to.

Comments