Total Pageviews

Friday, 11 September 2020

Termux 是一款能够为 Android 手机提供 Linux 环境的应用

 (https://termux.com/ , https://github.com/termux/termux-app , https://github.com/termux)

Termux支持 pkg 包管理来安装 python, nodejs,golang 等程序,是闲置手机废物利用的好助手。

安装 ssh 服务端

要知道使用传统键盘敲命令行的体验可是 Android 键盘不能比拟的,这里介绍下远程链接 Termux 的两种方式

pkg install openssh

安装完成后会在/data/data/com.termux/files/usr/etc/ssh/目录下生成几种常见的公钥/密钥对,以及sshd_configssh_config

安装好之后,我们需要手工启动 sshd,注意 sshd 监听的是 8022 端口而不是 22 号端口

# 启动
sshd

密码登陆

说明下 Termux 的 sshd 可以通过密码登陆的,不要相信网上的破教程,一个登陆搞这么麻烦

先说明下网络环境,我的电脑和手机都是连接的同一个 WIFI,手机的 IP 是 192.168.1.105

# 获取用户名
whoami
# 重置密码
passwd

切换到电脑,使用 ssh 命令登入,简单点也可以使用图形化的 xshell

# 这里使用任意用户名都可以登陆进去
# 因为Termux是单用户的,所以说上面的whoami没什么用处
ssh -p 8022 root@192.168.1.105
# 提示输入密码

1.png

密钥登陆

使用ssh-keygen命令生成公钥和私钥,默认参数会在~/.ssh目录下生成id_rsaid_rsa.pub这两个文件

主要的难度就是怎么把公钥给拷到电脑上,把公钥复制到 SD 卡然后找到文件通过 QQ 发给电脑就行了

另外 sshd_config 已经打开了密钥登录功能,无需再配置

# 申请SD卡读写权限
termux-setup-storage
cd ~/.ssh
# 服务器上安装公钥
cat id_rsa.pub >> authorized_keys
# 权限
chmod 600 authorized_keys
chmod 700 ~/.ssh
# 拷贝密钥到SD卡,顺便重命名了下
cp id_rsa /storage/emulated/0/Download/id_rsa_termux

切换到电脑,复制id_rsa_termuxC:\Users\用户名\.ssh

ssh -i C:\Users\tmaize\.ssh\id_rsa_termux -p 8022 root@192.168.1.105

如果你嫌命令太长,可以在C:\Users\用户名\.ssh下新建config文件,内容如下

Host termux
     HostName 192.168.1.105
     Port 8022
     IdentityFile C:/Users/tmaize/.ssh/id_rsa_termux
     PreferredAuthentications publickey
     User root

然后直接ssh termux就行了

包管理

下面是包管理的常用命令

pkg search <query>              搜索包
pkg install <package>           安装包
pkg uninstall <package>         卸载包
pkg reinstall <package>         重新安装包
pkg update                      更新源
pkg upgrade                     升级软件包
pkg list-all                    列出可供安装的所有包
pkg list-installed              列出已经安装的包
pkg shoe <package>              显示某个包的详细信息
pkg files <package>             显示某个包的相关文件夹路径

基本使用

速度慢的话可以换成国内源,注意有梯子话推荐使用默认源,不然可能会有一些奇怪的 bug

vi  $PREFIX/etc/apt/sources.list
# 修改为
# deb https://termux.net stable main
deb https://mirrors.tuna.tsinghua.edu.cn/termux/termux-packages-24 stable main

vi  $PREFIX/etc/apt/sources.list.d/science.list
# 修改为
# deb https://dl.bintray.com/grimler/science-packages-21 science stable
deb https://mirrors.tuna.tsinghua.edu.cn/termux/science-packages-24 science stable

vi  $PREFIX/etc/apt/sources.list.d/game.list
# 修改为
# deb https://dl.bintray.com/grimler/game-packages-21 games stable
deb https://mirrors.tuna.tsinghua.edu.cn/termux/game-packages-24 games stable

安装常用工具

pkg update
pkg install curl wget git unzip golang nodejs

开启访问外置存储

# 运行完成后会在家目录生成 storage 目录
# 会把 SD 卡下常用几个目录给链接进去
# 当然也可以使用绝对路径去访问,一般是/storage/emulated/0/
termux-setup-storage

当锁屏后,使用ssh远程连接输命令会特别卡,使用下面命令可以解决

termux-wake-lock

目录结构说明

# 这个相当于根目录
echo $PREFIX
/data/data/com.termux/files/usr

# 这个就是用户目录
echo $HOME
/data/data/com.termux/files/home

由于没有 root 权限,cd / ls 这个命令肯定是执行不了的,对此可以使用下面的命令来模拟

pkg install proot
termux-chroot # 一个新的用户登入,exit退出

cd /
ls -l # 看看有什么变化^o^

可以做什么

目前常见的就是做离线下载用了

常见的语言都是支持的,python,nodejs,golang 等,也可以安装其他二进制包但是注意要是 arm 版本的,所以几乎是可以做任何事情

另外在 windows 上交叉编译 golang 到 android 上运行可以使用下面的参数

set GOOS=linux
set GOARCH=arm

另外如果想公网访问可以使用 Ngrok 等服务.

-----------------------------------

Termux 高级终端安装使用配置教程

Termux 高级终端安装使用配置教程,刚写这篇文章的时候,当时国内 Termux 相关的文章和资料相对来说还是比较少的,就花了几天写了这一篇文章,没想到居然火了,受宠若惊。所以这篇文章国光就打算定期更新了,想打造成 termux 的中文文档,希望本文可以帮助到更多对 Termux 感兴趣的朋友,发挥 Android 平台更大的 DIY 空间。

学习资源

考虑到手机用户体验和离线观看教程的需求,国光打包了几种风格的 PDF版本,并且已经插入好目录,阅读体验会比较友好。

黑色背景的 PDF : Termux入门指南(Vue 黑)

白色背景的 PDF : Termux入门指南(Github 白)

macOS light风格 : Termux入门指南(macOS 白)

Gothic风格 : Termux入门指南(简约线条)

早期我的信息安全交流群里面陆陆续续加了很多 Temux 玩家,然而那是一个信息安全交流群,Termux 的提问经常没有人回答,所以后来我就把博客所有的加群链接给去了。现在国光我单独建立了 1 个Temux 群,加群链接藏在本文当中,是一个彩蛋,缘妙不可言,随缘入群吧。好了话不多说,教程开始了,希望本文可以帮助到大家。

Termux 简介

文档相关

下载地址

Google Play 下载的版本比酷安要新,而且插件这块安装也很方便,有能力的朋友建议首先考虑下载Google PLay版本的,然后考虑 F-Droid版本,最后再考虑可怜兮兮的酷安版本。

Termux 是一个 Android 下一个高级的终端模拟器,开源且不需要 root,支持 apt 管理软件包,十分方便安装软件包,完美支持 Python、 PHP、 Ruby、 Nodejs、 MySQL等。随着智能设备的普及和性能的不断提升,如今的手机、平板等的硬件标准已达到了初级桌面计算机的硬件标准,用心去打造 DIY 的话完全可以把手机变成一个强大的极客工具。

初始化

第一次启动Termux的时候需要从远程服务器加载数据,然而可能会遇到这种问题:Ubablto install

Termux was unable to install the bootstrap packages.
Check your network connection and try again.

这里的Termux官方远程的服务器地址是: http://termux.net/bootstrap/

目前解决方法有两种:

  1. VPN 全局代理 (成功率很高)
  2. 如果你是 WiFi 的话尝试切换到运营商流量 (有一定成功率)
  3. ① Google Play ② F-Droid ③ 酷安 根据这个顺序重复1、2操作

基本操作

基本操作还是要学习一下的,可以事半功倍。

缩放文本

可以使用缩放手势来调整其字体大小。 对就是 双指放大缩小照片那样操作。

长按屏幕

长按屏幕会调出显示菜单项(包括复制、粘贴、更多),方便我们进行复制或者粘贴.

More 菜单的说明如下:

长按屏幕
├── COPY:    # 复制
├── PASTE:   # 粘贴
├── More:    # 更多
   ├── Select URL:             # 提取屏幕所有网址
   └── Share transcipt:        # 分享命令脚本
   └── Reset:                  # 重置
   └── Kill process:           # 杀掉当前会话进程
   └── Style:                  # 风格配色 需要自行安装
   └── Keep screen on:         # 保持屏幕常亮
   └── Help:                   # 帮助文档

会话管理

显示隐藏式导航栏,可以新建、切换、重命名会话session和调用弹出输入法.

同时在Android的通知栏中也可以看到当前Termux运行的会话数.

常用按键

常用键是PC端常用的按键如: ESC键、Tab键、CTR键、ALT键,有了这些按键后可以提高我们日常操作的效率,所以Termux后面的版本默认都是显示这个扩展功能按键的。 (18年的时候默认是不显示的.)

打开和隐藏这个扩展功能按键目前有下面两种方法:

方法一

从左向右滑动,显示隐藏式导航栏,长按左下角的KEYBOARD

方法二

使用Termux快捷键:音量++Q键 或者 音量++K

当然这个常用按键在 Termux 后面的版本也支持自定义的,详情见本文的「进阶配置」-「定制常用按键」这一小节。

基础知识

这些基础知识简单了解一下就可以了,Linux 用的多了 就会慢慢熟悉理解了。

快捷键表

Ctrl键是终端用户常用的按键,但大多数触摸键盘都没有这个按键,因此 Termux 使用音量减小按钮来模拟Ctrl键。
例如,在触摸键盘上按音量减小L就相当于是键盘上按Ctrl + L的效果一样,达到清屏的效果。

  • Ctrl + A -> 将光标移动到行首
  • Ctrl + C -> 中止当前进程
  • Ctrl + D -> 注销终端会话
  • Ctrl + E -> 将光标移动到行尾
  • Ctrl + K -> 从光标删除到行尾
  • Ctrl + U -> 从光标删除到行首
  • Ctrl + L -> 清除终端
  • Ctrl + Z -> 挂起(发送SIGTSTP到)当前进程
  • Ctrl + alt + C -> 打开新会话(仅适用于 黑客键盘)

音量加键也可以作为产生特定输入的特殊键.

  • 音量加 + E -> Esc键
  • 音量加 + T -> Tab键
  • 音量加 + 1 -> F1(音量增加 + 2 → F2…以此类推)
  • 音量加 + 0 -> F10
  • 音量加 + B -> Alt + B,使用readline时返回一个单词
  • 音量加 + F -> Alt + F,使用readline时转发一个单词
  • 音量加 + X -> Alt+X
  • 音量加 + W -> 向上箭头键
  • 音量加 + A -> 向左箭头键
  • 音量加 + S -> 向下箭头键
  • 音量加 + D -> 向右箭头键
  • 音量加 + L -> | (管道字符)
  • 音量加 + H -> 〜(波浪号字符)
  • 音量加 + U -> _ (下划线字符)
  • 音量加 + P -> 上一页
  • 音量加 + N -> 下一页
  • 音量加 + . -> Ctrl + \(SIGQUIT)
  • 音量加 + V -> 显示音量控制
  • 音量加 + Q -> 切换显示的功能键视
  • 音量加 + K -> 切换显示的功能键视图

快捷键用的熟悉的话也可以极大提高操作的效率。

基本命令

Termux 除了支持 apt 命令外,还在此基础上封装了pkg命令,pkg 命令向下兼容 apt 命令。apt命令大家应该都比较熟悉了,这里直接简单的介绍下pkg命令:

pkg search <query>              # 搜索包
pkg install <package>           # 安装包
pkg uninstall <package>         # 卸载包
pkg reinstall <package>         # 重新安装包
pkg update                      # 更新源
pkg upgrade                     # 升级软件包
pkg list-all                    # 列出可供安装的所有包
pkg list-installed              # 列出已经安装的包
pkg show <package>              # 显示某个包的详细信息
pkg files <package>             # 显示某个包的相关文件夹路径

建议大家使用 pkg 命令,因为 pkg 命令每次安装的时候自动执行 apt update 命令,很是方便.

软件安装

除了通过上述的 pkg 命令安装软件以外,如果我们有 .deb 软件包文件,也可以使用 dpkg 进行安装:

dpkg -i ./package.de         # 安装 deb 包
dpkg --remove [package name] # 卸载软件包
dpkg -l                      # 查看已安装的包
man dpkg                     # 查看详细文档

目录结构

echo $HOME
/data/data/com.termux/files/home

echo $PREFIX
/data/data/com.termux/files/usr

echo $TMPPREFIX
/data/data/com.termux/files/usr/tmp/zsh

长期使用 Linux 的朋友可能会发现,这个HOME路径看上去和我们电脑端的不太一样,这是为了方便 Termux 提供的特殊的环境变量。

端口查看

Android 10 以下版本

Andorid 10 以下的版本是可以正常使用netstat 命令的,这样可以方便的查看端口开放信息:

# 查看所有端口
netstat -an

# 查看3306端口的开放情况
netstat -an|grep 3306

Android 10 版本

Andorid 10 版本的Termux 下无法正常使用 netstat -an 命令,国光的解决方法是安装一个 nmap,然后扫描本地端口(弯道超车):

# 安装nmap端口扫描神器
pkg install nmap

# 扫描本地端口
nmap 127.0.0.1

使用 nmap 操作 纯属无奈之举,但是又不是不能用(源于:罗永浩名言 :-))

进阶配置

要想使用体验好,进阶配置少不了。(单押)

更换国内源

使用pkg update 更新一下的时候发现默认的官方源网速有点慢,在这个喧嚣浮躁的时代,我们难以静下心等待,这个时候就得更换成国内的Termux清华大学源了,加快软件包下载速度。

方法一:自动替换(推荐)

可以使用如下命令自动替换官方源为 TUNA 镜像源

pkg update 卡住的话多按几次回车 不要傻乎乎的等.

sed -i 's@^\(deb.*stable main\)$@#\1\ndeb https://mirrors.tuna.tsinghua.edu.cn/termux/termux-packages-24 stable main@' $PREFIX/etc/apt/sources.list

sed -i 's@^\(deb.*games stable\)$@#\1\ndeb https://mirrors.tuna.tsinghua.edu.cn/termux/game-packages-24 games stable@' $PREFIX/etc/apt/sources.list.d/game.list

sed -i 's@^\(deb.*science stable\)$@#\1\ndeb https://mirrors.tuna.tsinghua.edu.cn/termux/science-packages-24 science stable@' $PREFIX/etc/apt/sources.list.d/science.list

pkg update

更换源几秒钟就可以执行完pkg update了,心里顿时乐开了花。

方法二:手动修改

请使用内置或安装在 Termux 里的文本编辑器,例如 vi / vim / nano 等直接编辑源文件,不要使用 RE 管理器等其他具有 ROOT 权限的外部 APP 来修改 Termux 的文件

编辑 $PREFIX/etc/apt/sources.list 修改为如下内容:

# The termux repository mirror from TUNA:
deb https://mirrors.tuna.tsinghua.edu.cn/termux/termux-packages-24 stable main

编辑 $PREFIX/etc/apt/sources.list.d/science.list 修改为如下内容:

# The termux repository mirror from TUNA:
deb https://mirrors.tuna.tsinghua.edu.cn/termux/science-packages-24 science stable

编辑 $PREFIX/etc/apt/sources.list.d/game.list 修改为如下内容:

# The termux repository mirror from TUNA:
deb https://mirrors.tuna.tsinghua.edu.cn/termux/game-packages-24 games stable

安装基础工具

更换源之后来赶紧来下载安装一些基本工具吧,这些工具基本上是 Linux 系统自带的,因为 Termux 为了体积不过大,默认是没有带这些工具的,执行下面的命令来安装:

pkg update
pkg install vim curl wget git tree -y

终端配色方案

脚本项目地址https://github.com/Cabbagec/termux-ohmyzsh/

该脚本主要使用了zsh来替代bash作为默认 shell,并且支持色彩和字体样式,同时也激活了外置存储,可以直接访问SD卡下的目录。主题默认为 agnoster,颜色样式默认为 Tango,字体默认为 Ubuntu。

执行下面这个命令确保已经安装好了curl:

sh -c "$(curl -fsSL https://github.com/Cabbagec/termux-ohmyzsh/raw/master/install.sh)"  

如果因为不可抗力的原因,出现port 443: Connection refused网络超时的情况,那么挂上vpn,再执行一次。

Android6.0 以上会弹框确认是否授权访问文件,点击始终允许授权后 Termux 可以方便的访问SD卡文件。

手机 App 默认只能访问自己的数据,如果要访问手机的存储,需要请求权限,如果你刚刚不小心点了拒绝的话,那么可以执行以下命令来重新获取访问权限:

termux-setup-storage

脚本允许后先后有如下两个选项:

Enter a number, leave blank to not to change: 14
Enter a number, leave blank to not to change: 6

分别选择色彩样式字体样式,重启Termux app后生效配置。不满意刚刚的效果,想要继续更改配色方案的话,可以根据下面命令来更改对应的色彩配色方案:

设置色彩样式

输入chcolor命令更换色彩样式,或者:~/.termux/colors.sh命令

设置字体

运行chfont更换字体,或者:~/.termux/fonts.sh命令

创建目录软连接

执行过上面的一键配置脚本后,并且授予 Termux 文件访问权限的话,会在家目录生成storage目录,并且生成若干目录,软连接都指向外置存储卡的相应目录:


创建QQ文件夹软连接

手机上一般经常使用手机QQ来接收文件,这里为了方便文件传输,直接在storage目录下创建软链接.
QQ:

ln -s /data/data/com.termux/files/home/storage/shared/tencent/QQfile_recv QQ

这样可以直接在home目录下去访问QQ文件夹,大大提升了工作效率。

定制常用按键

在 Termux v0.66 的版本之后我们可以通过 ~/.termux/termux.properties 文件来定制我们的常用功能按键,默认是不存在这个文件的,我们得自己配置创建一下这个文件。

下面做尝试简单配置一下这个文件:

# 新建并编辑配置文件
vim ~/.termux/termux.properties

内容为:

extra-keys = [ \
 ['ESC','|','/','HOME','UP','END','PGUP','DEL'], \
 ['TAB','CTRL','ALT','LEFT','DOWN','RIGHT','PGDN','BKSP'] \
]

如果无法创建这个文件,那么得首先新建一下这个目录 mkdir ~/.termux

修改完成保存文件后,重启 Termux app生效配置.

可以直接输入特殊的字符串,例如上面的例子中的|就是一个字符串,此外 Termux 还有封装了一些特殊按键,入上面例子中的ESC就是 Termux 自带的按键,完整的特殊按键表如下:

按键说明
CTRL特殊按键
ALT特殊按键
FN特殊按键
ESC退出键
TAB表格键
HOME原位键
END结尾键
PGUP上翻页键
PGDN下翻页键
INS插入键
DEL删除键
BKSP退格键
UP方向键 上
LEFT方向键 左
RIGHT方向键 右
DOWN方向键 下
ENTER回车键
BACKSLASH反斜杠 \
QUOTE双引号键
APOSTROPHE单引号键
F1~F12F1-F12按键

上面列出的三个特殊键中的每一个最多只能在附加键定义中列出一次,超过次数将会报错。

下面是我自用的按键表:

extra-keys = [ \
 ['ESC','|','/','`','UP','QUOTE','APOSTROPHE'], \
 ['TAB','CTRL','~','LEFT','DOWN','RIGHT','ENTER'] \
]

zsh插件推荐

zsh 之所以受欢迎除了好看的配色以为,另一个原因就是强大的插件了。下面列举一款比较实用的插件的安装方法,更多强大的插件等待大家自己去探索。

autosuggestions

根据用户的平时使用习惯,终端会自动提示接下来可能要输入的命令,这个实际使用效率还是比较高的:

# 拷贝到 plugins 目录下
git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions

在 ~/.zshrc 中配置:

plugins=(其他的插件 zsh-autosuggestions)

超级管理员身份

实际上 Termux 不需要 root 权限也可以折腾各种各样的操作的,大家不必对 root 抱有啥幻想,本文的操作基本上没有涉及到手机要用到 root 的地步。

手机没有root

利用proot可以为手机没有root的用户来模拟一个root的环境,这里主要是经典的 Linux 文件系统布局上的模拟。

pkg install proot -y

然后终端下面输入:

termux-chroot

即可模拟root环境,该环境模仿 Termux 中的常规Linux文件系统,但不是真正的 root。

输入exit可回到普通用户的文件系统。

手机已经root

安装tsu,这是一个su的 Termux 版本,是一个真正的root权限,用来在termux上替代su,操作不慎可能对手机有安全风险。因为官方封装了,所以安装也很简单:

pkg install tsu -y

然后终端下面输入:

tsu

即可切换root用户,这个时候会弹出root授权提示,给予其root权限.

在管理员身份下,输入exit可回到普通用户身份。不过本文没有设计到 root 权限的操作,一些底层的工具可能才会需要,考虑到 root 的不安全性 和 那些工具的冷门性,这里就没有继续拓展。

开发环境

Termux 支持的开发环境很强,可以完美的运行 C、Python、Java、PHP、Ruby等开发环境,建议读者朋友们选择自己需要的开发环境折腾。

编辑器

写代码前总得折腾一下编辑器,毕竟磨刀不误砍柴工嘛。Termux 支持多种编辑器,完全可以满足日常使用需求。

Emacs

据说Emacs是神的编辑器,国光我这种小菜鸡还不会使用哎,但是 Termux 官方已经封装好了 Emacs了,我们安装起来就会简单很多:

Bash
pkg install emacs  

nano

nano 是一个小而美的编辑器。具有如下:打开多个文件,每行滚动,撤消/重做,语法着色,行编号等功能

同样安装起来也很简单:

Bash
pkg install nano
from http://web.archive.org/web/20210717103926/https://www.sqlsec.com/2018/05/termux.html

---------

使用 Termux 将手机变成 Linux 服务器

你平时是怎样将手机上的文件传到电脑上的呢, 使用数据线? 还是下载专门的软件? 这些都太麻烦了, 完全可以借用 Termux 在手机端跑一个 Web 服务器, 让电脑端访问, 直接下载文件.

你也可以将旧手机利用起来, 让它继续发光发热, 像树莓派一样运行各种有趣的程序.

什么是 Termux?

Termux 是一个 Android 的 APP, 可以模拟 Linux 环境, 在手机上执行 Linux 命令, 不需要 root, 安装即可用.

安装 Termux

首先, 下载 Termux 你可以去 Google Play 或 APKPure 下载.

环境准备

更新一下系统, 确保使用最新版本:

# 连接远程仓库,获取软件包信息
$ apt update

# 更新本地已经安装的软件包
$ apt upgrade

测试系统:

# 安装 sl 软件包
$ apt install sl

# 运行
$ sl

命令行输入 sl 后出现一辆运行着的小火车动画则成功.

访问手机储存

Termux 默认状态下只能访问自己的数据, 如果要访问手机储存, 需要设置权限:

$ termux-setup-storage

执行上面的命令以后, 会跳出一个对话框, 询问是否允许 Termux 访问手机存储, 点击”允许”.

这会在当前目录下生成一个storage子目录, 它是手机存储的符号链接, 后文下载文件就是到这个目录去下载.

软件包管理

除了apt命令, Termux 还提供pkg命令进行软件包管理.

# 安装软件包
$ pkg install [package name]

# 卸载软件包
$ pkg uninstall [package name]

# 列出所有软件包
$ pkg list-all

其实, pkg 的底层就是 apt, 只是运行前会执行一次 apt update, 保证安装的是最新版本. 所以, apt install sl 基本等同于 pkg install sl.

使用 Python 架设简易服务器

使用下面的命令安装 Python 并开启简易服务器:

$ apt install python
$ python -m http.server 8080

接下来, 就可以在同一网络下在电脑上输入手机的 IP地址:端口号 的方式, 访问并下载手机上的文件了.

ifconfig 命令可以查看当前 IP 地址.

另外, 手机现在相当于一台 Linux 服务器, 所以也可以用 SSH, Nginx 等连接, 也可以架设 VPN 服务用作进入校园网的工具, 总之感觉很强大, 更多使用方法等你去发掘.

其他设置

为 Termux 更换国内镜像源

将镜像源改为国内是为了加快软件包的下载速度, 在下载软件包速度不佳时可尝试此步骤.

输入如下命令:

export EDITOR=vi  
apt edit-sources

将其中的内容替换为:

# The termux repository mirror from TUNA:
deb [arch=all,arm] https://mirrors.tuna.tsinghua.edu.cn/termux stable main

完.

鸣谢

  • termux-config
  • Termux入门教程-架设手机 Server 下载文件: https://www.ruanyifeng.com/blog/2019/07/termux-tutorial.html

------------------------------------

https://github.com/termux/termux-packages

------------------------------------------------------------------------

Termux - a terminal emulator application for Android OS extendible by variety of packages.

https://f-droid.org/en/packages/com.termux

Termux application

Build status Testing status Join the chat at https://gitter.im/termux/termux Join the Termux discord server Termux library releases at Jitpack

Termux is an Android terminal application and Linux environment.

Note that this repository is for the app itself (the user interface and the terminal emulation). For the packages installable inside the app, see termux/termux-packages.

Quick how-to about Termux package management is available at Package Management. It also has info on how to fix repository is under maintenance or down errors when running apt or pkg commands.

We are looking for Termux Android application maintainers.

NOTICE: Termux may be unstable on Android 12+. Android OS will kill any (phantom) processes greater than 32 (limit is for all apps combined) and also kill any processes using excessive CPU. You may get [Process completed (signal 9) - press Enter] message in the terminal without actually exiting the shell process yourself. Check the related issue #2366, issue tracker, phantom cached and empty processes docs and this TLDR comment on how to disable trimming of phantom and excessive cpu usage processes. A proper docs page will be added later. An option to disable the killing should be available in Android 12L or 13, so upgrade at your own risk if you are on Android 11, specially if you are not rooted.

Contents

Termux App and Plugins

The core Termux app comes with the following optional plugin apps.

Installation

Latest version is v0.118.0.

NOTICE: It is highly recommended that you update to v0.118.0 or higher ASAP for various bug fixes, including a critical world-readable vulnerability reported here. See below for information regarding Termux on Google Play.

Termux can be obtained through various sources listed below for only Android >= 7 with full support for apps and packages.

Support for both app and packages was dropped for Android 5 and 6 on 2020-01-01 at v0.83, however it was re-added just for the app without any support for package updates on 2022-05-24 via the GitHub sources. Check here for the details.

The APK files of different sources are signed with different signature keys. The Termux app and all its plugins use the same sharedUserId com.termux and so all their APKs installed on a device must have been signed with the same signature key to work together and so they must all be installed from the same source. Do not attempt to mix them together, i.e do not try to install an app or plugin from F-Droid and another one from a different source like GitHub. Android Package Manager will also normally not allow installation of APKs with different signatures and you will get errors on installation like App not installed, Failed to install due to an unknown error, INSTALL_FAILED_UPDATE_INCOMPATIBLE, INSTALL_FAILED_SHARED_USER_INCOMPATIBLE, signatures do not match previously installed version, etc. This restriction can be bypassed with root or with custom roms.

If you wish to install from a different source, then you must uninstall any and all existing Termux or its plugin app APKs from your device first, then install all new APKs from the same new source. Check Uninstallation section for details. You may also want to consider Backing up Termux before the uninstallation so that you can restore it after re-installing from Termux different source.

In the following paragraphs, "bootstrap" refers to the minimal packages that are shipped with the termux-app itself to start a working shell environment. Its zips are built and released here.

F-Droid

Termux application can be obtained from F-Droid from here.

You do not need to download the F-Droid app (via the Download F-Droid link) to install Termux. You can download the Termux APK directly from the site by clicking the Download APK link at the bottom of each version section.

It usually takes a few days (or even a week or more) for updates to be available on F-Droid once an update has been released on GitHub. The F-Droid releases are built and published by F-Droid once they detect a new GitHub release. The Termux maintainers do not have any control over the building and publishing of the Termux apps on F-Droid. Moreover, the Termux maintainers also do not have access to the APK signing keys of F-Droid releases, so we cannot release an APK ourselves on GitHub that would be compatible with F-Droid releases.

The F-Droid app often may not notify you of updates and you will manually have to do a pull down swipe action in the Updates tab of the app for it to check updates. Make sure battery optimizations are disabled for the app, check https://dontkillmyapp.com/ for details on how to do that.

Only a universal APK is released, which will work on all supported architectures. The APK and bootstrap installation size will be ~180MB. F-Droid does not support architecture specific APKs.

GitHub

Termux application can be obtained on GitHub either from GitHub Releases for version >= 0.118.0 or from GitHub Build Action workflows. For android >= 7, only install apt-android-7 variants. For android 5 and 6, only install apt-android-5 variants.

The APKs for GitHub Releases will be listed under Assets drop-down of a release. These are automatically attached when a new version is released.

The APKs for GitHub Build action workflows will be listed under Artifacts section of a workflow run. These are created for each commit/push done to the repository and can be used by users who don't want to wait for releases and want to try out the latest features immediately or want to test their pull requests. Note that for action workflows, you need to be logged into a GitHub account for the Artifacts links to be enabled/clickable. If you are using the GitHub app, then make sure to open workflow link in a browser like Chrome or Firefox that has your GitHub account logged in since the in-app browser may not be logged in.

The APKs for both of these are debuggable and are compatible with each other but they are not compatible with other sources.

Both universal and architecture specific APKs are released. The APK and bootstrap installation size will be ~180MB if using universal and ~120MB if using architecture specific. Check here for details.

Security warning: APK files on GitHub are signed with a test key that has been shared with community. This IS NOT an official developer key and everyone can use it to generate releases for own testing. Be very careful when using Termux GitHub builds obtained elsewhere except https://github.com/termux/termux-app. Everyone is able to use it to forge a malicious Termux update installable over the GitHub build. Think twice about installing Termux builds distributed via Telegram or other social media. If your device get caught by malware, we will not be able to help you.

The test key shall not be used to impersonate @termux and can't be used for this anyway. This key is not trusted by us and it is quite easy to detect its use in user generated content.

Keystore information

Google Play Store (Experimental branch)

There is currently a build of Termux available on Google Play for Android 11+ devices, with extensive adjustments in order to pass policy requirements there. This is under development and has missing functionality and bugs (see here for status updates) compared to the stable F-Droid build, which is why most users who can should still use F-Droid or GitHub build as mentioned above.

Currently, Google Play will try to update installations away from F-Droid ones. Updating will still fail as sharedUserId has been removed. A planned 0.118.1 F-Droid release will fix this by setting a higher version code than used for the PlayStore app. Meanwhile, to prevent Google Play from attempting to download and then fail to install the Google Play releases over existing installations, you can open the Termux apps pages on Google Play and then click on the 3 dots options button in the top right and then disable the Enable auto update toggle. However, the Termux apps updates will still show in the PlayStore app updates list.

If you want to help out with testing the Google Play build (or cannot install Termux from other sources), be aware that it's built from a separate repository (https://github.com/termux-play-store/) - be sure to report issues there, as any issues encountered might very well be specific to that repository.

Uninstallation

Uninstallation may be required if a user doesn't want Termux installed in their device anymore or is switching to a different install source. You may also want to consider Backing up Termux before the uninstallation.

To uninstall Termux completely, you must uninstall any and all existing Termux or its plugin app APKs listed in Termux App and Plugins.

Go to Android Settings -> Applications and then look for those apps. You can also use the search feature if it’s available on your device and search termux in the applications list.

Even if you think you have not installed any of the plugins, it's strongly suggested to go through the application list in Android settings and double-check.

Important Links

Community

All community links are available here.

The main ones are the following.

Wikis

Miscellaneous

Terminal

Debugging

You can help debug problems of the Termux app and its plugins by setting appropriate logcat Log Level in Termux app settings -> <APP_NAME> -> Debugging -> Log Level (Requires Termux app version >= 0.118.0). The Log Level defaults to Normal and log level Verbose currently logs additional information. Its best to revert log level to Normal after you have finished debugging since private data may otherwise be passed to logcat during normal operation and moreover, additional logging increases execution time.

The plugin apps do not execute the commands themselves but send execution intents to Termux app, which has its own log level which can be set in Termux app settings -> Termux -> Debugging -> Log Level. So you must set log level for both Termux and the respective plugin app settings to get all the info.

Once log levels have been set, you can run the logcat command in Termux app terminal to view the logs in realtime (Ctrl+c to stop) or use logcat -d > logcat.txt to take a dump of the log. You can also view the logs from a PC over ADB. For more information, check official android logcat guide here.

Moreover, users can generate termux files stat info and logcat dump automatically too with terminal's long hold options menu More -> Report Issue option and selecting YES in the prompt shown to add debug info. This can be helpful for reporting and debugging other issues. If the report generated is too large, then Save To File option in context menu (3 dots on top right) of ReportActivity can be used and the file viewed/shared instead.

Users must post complete report (optionally without sensitive info) when reporting issues. Issues opened with (partial) screenshots of error reports instead of text will likely be automatically closed/deleted.

Log Levels
  • Off - Log nothing.
  • Normal - Start logging error, warn and info messages and stacktraces.
  • Debug - Start logging debug messages.
  • Verbose - Start logging verbose messages.

For Maintainers and Contributors

The termux-shared library was added in v0.109. It defines shared constants and utils of the Termux app and its plugins. It was created to allow for the removal of all hardcoded paths in the Termux app. Some of the termux plugins are using this as well and rest will in future. If you are contributing code that is using a constant or a util that may be shared, then define it in termux-shared library if it currently doesn't exist and reference it from there. Update the relevant changelogs as well. Pull requests using hardcoded values will/should not be accepted. Termux app and plugin specific classes must be added under com.termux.shared.termux package and general classes outside it. The termux-shared LICENSE must also be checked and updated if necessary when contributing code. The licenses of any external library or code must be honoured.

The main Termux constants are defined by TermuxConstants class. It also contains information on how to fork Termux or build it with your own package name. Changing the package name will require building the bootstrap zip packages and other packages with the new $PREFIX, check Building Packages for more info.

Check Termux Libraries for how to import termux libraries in plugin apps and Forking and Local Development for how to update termux libraries for plugins.

The versionName in build.gradle files of Termux and its plugin apps must follow the semantic version 2.0.0 spec in the format major.minor.patch(-prerelease)(+buildmetadata). When bumping versionName in build.gradle files and when creating a tag for new releases on GitHub, make sure to include the patch number as well, like v0.1.0 instead of just v0.1. The build.gradle files and attach_debug_apks_to_release workflow validates the version as well and the build/attachment will fail if versionName does not follow the spec.

Commit Messages Guidelines

Commit messages must use the Conventional Commits spec so that chagelogs as per the Keep a Changelog spec can automatically be generated by the create-conventional-changelog script, check its repo for further details on the spec. The first letter for type and description must be capital and description should be in the present tense. The space after the colon : is necessary. For a breaking change, add an exclamation mark ! before the colon :, so that it is highlighted in the chagelog automatically.

<type>[optional scope]: <description>

[optional body]

[optional footer(s)]

Only the types listed below must be used exactly as they are used in the changelog headings. For example, Added: Add foo, Added|Fixed: Add foo and fix bar, Changed!: Change baz as a breaking change, etc. You can optionally add a scope as well, like Fixed(terminal): Fix some bug. Do not use anything else as type, like add instead of Added, etc.

  • Added for new features.
  • Changed for changes in existing functionality.
  • Deprecated for soon-to-be removed features.
  • Removed for now removed features.
  • Fixed for any bug fixes.
  • Security in case of vulnerabilities.

Forking

  • Check TermuxConstants javadocs for instructions on what changes to make in the app to change package name.
  • You also need to recompile bootstrap zip for the new package name. Check building bootstrap, here and here.
  • Currently, not all plugins use TermuxConstants from termux-shared library and have hardcoded com.termux values and will need to be manually patched.
  • If forking termux plugins, check Forking and Local Development for info on how to use termux libraries for plugins.
from https://github.com/termux/termux-app

------------------------------ 

Linux installer for termux  .

Atilo

A program to install linux on termux

Test

中文用户点击这里

Installation

echo "deb [trusted=yes arch=all] https://yadominjinta.github.io/files/ termux extras" >> $PREFIX/etc/apt/sources.list.d/atilo.list
apt update && apt install atilo

Usage

atilo [command] [Arguments]
Atilo           2.0
Usage: atilo [Command] [Argument]

Atilo is a program to help you install some GNU/Linux distributions on Termux.

Commands:
images           list available images
remove           remove installed images
pull             pulling an image
run              run an image
clean            clean tmps
help             show this help.

Support Linux

Distribution aarch64 arm x86_64 i686
Alpine
CentOS × ×
Debian
Fedora ×
Kali
openSUSE × ×
Ubuntu

GUI

Using GUI on termux

Group

Telegram:Termux Group ZH_CN

Relate Projects

EXALAB/AnLinux-App: APP to help install Linux on termux.
sdrausty/TermuxArch: Arch install script
Neo-Oli/termux-ubuntu: Ubuntu chroot on termux
Hax4us/Nethunter-In-Termux: Install Kali nethunter (Kali Linux) in your termux application without rooted phone
nmilosev/termux-fedora: A script to install a Fedora chroot into Termux
sp4rkie/debian-on-termux: Install Debian 9 (stretch) on your Android smartphone

Hax4us/TermuxAlpine: Use TermuxAlpine.sh calling to install Alpine Linux in Termux on Android.

from https://github.com/YadominJinta/atilo

 

No comments:

Post a Comment