Termux is a free and open-source terminal emulator for Android which allows for running a Linux environment on an Android device.
Source: Wikipedia
The main function we’re using with Termux on Android is the ability to clone and work with repositories hosted on Gitlab. In order to seamlessly git pull and git push these repositories, it is best to set up an SSH key on the Anrdoid device, and connect it to Gitlab.
First we’ll install Git in Termux:
- Update Termux packages:
pkg update && pkg upgrade - Install Git using the package manager:
pkg install git - Check if Git is correctly installed:
git --version - Set up your Git configuration:
- Your user name:
git config --global user.name "Your Name" - Your email:
git config --global user.email "email@example.com"
- Your user name:
This documentation is a step-by-step guide to set up SSH in Termux, on an Android device.
- Update Termux packages:
pkg update && pkg upgrade - Install OpenSSH:
pkg install openssh - Generate SSH keys:
ssh-keygen -t ed25519 -C "email@example.com"- When prompted, press Enter to accept the default file location
- Enter a secure passphrase or press Enter for no passphrase
- Start the SSH agent:
eval "$(ssh-agent -s)" - Add your key to SSH agent:
ssh-add ~/.ssh/id_ed25519 - Display you public key:
cat ~/.ssh/id_ed25519.puband copy the entire output - Then, we need to add this output to our Gitlab account
- Log in to your Gitlab account using a web browser
- Go tu User Settings > SSH Keys
- Paste your public key into the “Key” field
- Give it a descriptive title
- Click “Add key”
- Test your connection to Gitlab:
ssh -T git@gitlab.com - You can now clone repositories from Gitlab using SSH:
git clone git@gitlab.com:username/repository.git
The steps 4 and 5 of the previous guide must be done every time Termux is launched. In order to do that automatically, and avoid having to re-enter the passphrase every time we push, pull, or clone a repository, it is possible to modify the .bashrc file in Termux that will run these two lines of code every time Termux is launched:
- On Termux launch, run:
nano ~/.bashrcto create and open the.bashrcfile using the nano editor - Then, enter these two lines of code in the file:
eval $(ssh-agent -s)
ssh-add ~/.ssh/id_ed25519- Save the file by pressing
Ctrl+X, thenY, thenEnter. - Ensure that
~/.bashrcis executable:chmod +x ~/.bashrc - To apply the changes immediatly, source the
~/.bashrcfile:source ~/.bashrc - To test if the SSH agent is running and the key is added, run:
ssh-add -l - If you’re using a passphrase for your SSH key, you’ll need to enter it once per session when the key is added