Termux 是一款Android 终端模拟器和 Linux 环境应用程序,无需 root 或设置即可直接运行。自动安装最小的基本系统 - 使用 APT 包管理器可以使用其他包。
下载
play商店的版本是老版本,建议安装最新版本。如果是Play版本,大概率会碰到403的问题(需要执行apt upgrade -y)。
从 F-Droid 下载
开光
apt update -y
pkg install -y vim termux-services openssh nmap wget
远程连接
安装过openssh后,在电脑上操作就更简单了
# 安装ssh服务
pkg install openssh -y
# 运行SSH Server
sshd
通过密码方式
# 设置密码
passwd
# 获得Android IP
ifconfig | grep inet
## PC端连接
androidIP:8022
通过公钥方式
# 在Android上执行
ssh-keygen
# 添加到授信列表
cd /data/data/com.termux/files/home/.ssh/
cat id_rsa.pub >> authorized_keys
pkill sshd
sshd
通过服务方式启动
| Package | Daemon | Port | Description |
|---|---|---|---|
| apache2 | httpd | 8080 | Apache Web Server HTTP Web Server |
| at | atd | AT and batch delayed command scheduling utility and daemon at | |
| bitcoin | bitcoind | Bitcoin Core | |
| busybox | telnetd | 8023 | Remote terminal service Telnet |
| busybox | ftpd | 8021 | FTP (File Transfer Protocol) FTP |
| cronie | crond | Daemon that runs specified programs at scheduled times cron | |
| emacs | emacsd | Extensible, customizable text editor-and more EMACS | |
| ipfs | ipfs | A peer-to-peer hypermedia distribution protocol IPFS | |
| libmosquitto | mosquitto | 1883 | MQTT is a lightweight, publish-subscribe network protocol MQTT |
| lighttpd | lighttpd | 8080 | Lighttpd Small webserver HTTP Web Server |
| lnd | lnd | Lightning Network Daemon | |
| mariadb | mysqld | 3306 | MariaDB Community-developed fork of the MySQL from its original authors |
| mpd | mpd | Music Player Daemon (MPD) | |
| mpdscribble | mpdscribble | MPD client which submits tracks being played | |
| nginx | nginx | 8080 | NGINX Web server HTTP Web Server |
| openssh | sshd | 8022 | OpenSSH SSH |
| postgresql | postgres | 5432 | PostgreSQL database PostgreSQL |
| privoxy | privoxy | Privoxy is non-caching web proxy with advanced filtering capabilities HTTP Proxy | |
| tor | tor | The Onion Router anonymizing overlay network Tor | |
| transmission | transmission | BitTorrent client BitTorrent |
在安装 termux-services 完成后,需要重启app(杀进程)
# 启动服务,并设置为开机启动
sv-enable <service>
# 运行服务
sv up <service>
# 停止服务
sv down <service>
# 禁用服务
sv-disable <service>
例如:
pkg install nginx -y
sv-enable nginx
开机启动
需安装APP:Termux:Boot 运行一次,并添加到电池优化白名单
添加配置
mkdir ~/.termux/boot/
vim ~/.termux/boot/startup.sh
#!/data/data/com.termux/files/usr/bin/sh
termux-wake-lock # 防止休眠
. $PREFIX/etc/profile # Termux-services
赋予执行权限
chmod +x ~/.termux/boot/startup.sh
Docker
目前的方案是,模拟x86,然后运行Docker。效率感人
原作者
的后续步骤看不懂了,暂时不折腾
另外一个方案 ,需要编译Android内核。但是不需要虚拟机了
# 安装必要的包
pkg install -y qemu-utils qemu-common qemu-system-x86_64-headless
# 下载镜像
wget https://dl-cdn.alpinelinux.org/alpine/v3.14/releases/x86_64/alpine-virt-3.14.2-x86_64.iso
# 创建硬盘
qemu-img create -f qcow2 alpine.img 4G
# 启动
qemu-system-x86_64 -machine q35 -m 1024 -smp cpus=2 -cpu qemu64 \
-drive if=pflash,format=raw,read-only,file=$PREFIX/share/qemu/edk2-x86_64-code.fd \
-netdev user,id=n1,hostfwd=tcp::2222-:22 -device virtio-net,netdev=n1 \
-cdrom alpine-virt-3.12.3-x86_64.iso \
-nographic alpine.img
# 启动完成后,使用root登录,没有密码
# 设置网络
setup-interfaces
ifup eth0
# 安装
wget https://gist.githubusercontent.com/oofnikj/e79aef095cd08756f7f26ed244355d62/raw/answerfile
sed -i -E 's/(local kernel_opts)=.*/\1="console=ttyS0"/' /sbin/setup-disk
setup-alpine -f answerfile
其他工具
# golang
wget https://golang.org/dl/go1.17.2.linux-arm64.tar.gz
# mysql
pkg install mariadb
刷Linux原生系统(类似LineageOS) https://postmarketos.org/
弱弱的问一下,android手机为什么不能刷linux?
https://www.zhihu.com/question/277198849