radicaledward101

Cloning My Site's Git Repo on Android to Write on the Go

I’m writing this entirely from my Android phone! I spent quite a few hours trying to figure out how to get a clone of my git repository on here and hit a lot of dead ends. I tried multiple sets of instructions for AIDE and mGit with no success. Finally I found the Termux app which actually supports everything I need! For some reason Termux was not coming up in any of my searches for git clients on Android. Please improve your SEO!

With Termux I was able to get my repository cloned from GitHub just like I would on desktop. Now I should be able to write directly to my site on the go. In the future I’m going to try to get Hugo itself running on here. There’s some indication that this is possible. But for now I will just be copying the frontmatter from previous articles to create new ones. I’ll check in the articles with git and then run Hugo and update my website the next time I’m in front of a computer.

Even with Termux, setup was not entirely straight forward.

I used an archived copy of the guide from pedronveloao.com as a reference. It appears to be down but a cached copy is available at archive.org. Note that this guide was missing steps for setting up the ssh agent.

Specifically I needed to run

eval $(ssh-agent)

to start the ssh auth client and

ssh-add

to add the keys that I had moved to my ~/.ssh folder.

In addition I found the instructions for moving keys to the proper place to be confusing. They might make sense if you are using the same set of keys for multiple devices, but I would recommend using a separate set for your phone. That way you can disallow them later if it gets stolen or lost. Luckily OpenSSH creates some keys on install that I was able to use.

To copy those keys to the default location for the ash agent I ran the following:

cd /data/data/com.termux/files/usr/etc/ssh
cp ssh_host_ed25519_key ~/.ssh/
cp ssh_host_ed25519_key.pub ~/.ssh/

So to sum it all up:

  1. Install the Termux app with F-Droid
  2. apt update && apt upgrade
  3. pkg install termux-api
  4. apt install git
  5. apt install openssh
  6. cd /data/data/com.termux/files/usr/etc/ssh
  7. cp ssh_host_ed25519_key ~/.ssh/
  8. cp ssh_host_ed25519_key.pub ~/.ssh/
  9. run termux-setup-storage (to give Termux access to app shared storage. Note that a permissions pop-up will appear)
  10. If your ssh pub key is not setup on GitHub yet, then you should add it now. You can copy it to your clipboard with cat ~/.ssh/ssh_host_ed25519_key.pub | termux-clipboard-set. Just make sure it is the public key and not the private one!
  11. eval $(ssh-agent)
  12. ssh-add ~/.ssh/ssh_host_ed25519_key
  13. Confirm the addition with ssh-add -l
  14. cd ~/storage/shared/\<desired git project parent folder\>
  15. git clone as you would on any normal computer
  16. Do some work - I’m using hugo more info here
  17. Attempt git commit as normal
  18. On screen instructions will have you setup your user.name and user.email
  19. Run git commit again.
  20. Use vim to write a commit message. At this point you need to know how to get the escape key for use with vim. It’s “Volume Up + e”. There are more useful keyboard shortcuts listed on Termux’s website. If you want to forget all that, use the -m flag for your message.
  21. git push

After that there are a number of editors available that will let you update the files. I’m using Epsilon right now because I’m only going to be doing Markdown editing for Hugo. To be honest I’m not terribly impressed, but it does seem to do an ok job.

Because of the way OpenSSH works, I believe you probably need to rerun the eval $(ssh-agent) and ssh-add commands on every restart. I bet Termux has a good way of dealing with this (maybe a bash profile or something?) But for now I’m going to do it manually until it hurts. (me from the future: I’ve since found that this is not true. The openssh setting persist across sessions just fine!)

Obviously these instructions were focused on GitHub because that’s the git host I’m using, but I would bet that all of this will work well regardless. I believe this should support https clone too. However I would definitely recommend ssh.

UPDATE 2022-11-26:

It has now been 4 and a half years since I started writing blog posts on my phone and a few things have changed: