使用Termux打造你的移动开发平台

使用ssh连接Termux

  • 更新apt
apt update
  • 安装openssh
apt install openssh
  • 查看用户名
$ whoami
u0_a79
  • 设置密码
passwd
  • 查看当前ip地址
~ $ ifconfig
Warning: cannot open /proc/net/dev (Permission denied). Limited output.
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 1000  (UNSPEC)

tun0: flags=81<UP,POINTOPOINT,RUNNING>  mtu 9000
        inet 172.19.0.1  netmask 255.255.255.252  destination 172.19.0.1
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 500  (UNSPEC)

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.3.3  netmask 255.255.255.0  broadcast 192.168.3.255
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 3000  (UNSPEC)
  • 开启ssh服务
~ $ sshd -d
debug1: sshd version OpenSSH_9.7, OpenSSL 3.2.1 30 Jan 2024
debug1: private host key #0: ssh-rsa SHA256:0EYy1BrF8JF0qkchZmjF/bO/oKZBqWGZUXxXqUUB8Fs
debug1: private host key #1: ecdsa-sha2-nistp256 SHA256:yn7uCc8krimPRIS2upGITOzToDzmseBtpQkg0Ko45A8
debug1: private host key #2: ssh-ed25519 SHA256:mIHjgpYc1ohYLMGqmg29OEl+EwGiP7WpcqmCFuUctBo
debug1: rexec_argv[0]='/data/data/com.termux/files/usr/bin/sshd'
debug1: rexec_argv[1]='-d'
debug1: Bind to port 8022 on ::.
Server listening on :: port 8022.
debug1: Bind to port 8022 on 0.0.0.0.
Server listening on 0.0.0.0 port 8022.
  • 使用pc端连接android 端termux

确保在同一局域网内

ssh u0_a79@192.168.3.3 -p 8022

输入前面设置的密码后,即可连接成功

开启root模式

  • 安装git
apt install git
  • 下载root库
git clone https://github.com/hctilg/root-termux.git
cd root-termux/
  • 安装依赖
 apt install wget proot -y
  • 安装root
bash install.sh
  • 开启root
bash start.sh

termux多窗口

这部分要在手机上操作,别用ssh

  • 退出root
exit
  • 安装tmux
apt install tmux
  • 启动tmux
tmux
  • 创建窗口上下分屏

ctrl + b 然后再按"

  • 切换窗口

直接用鼠标点击或者 ctrl + b 然后再按方向键

使用cpolar进行内网穿透

这部分要在手机上操作,别用ssh

  • 进入root模式
bash start.sh
  • 使用tmux创建两个窗口
tmux
ctrl + b 然后按"
  • 安装依赖
apt update
apt install wget
apt-get install init
  • 下载cpolar安装脚本
wget https://www.cpolar.com/static/downloads/install-release-cpolar.sh
  • 安装cpolar
bash install-release-cpolar.sh
  • 配置cpolar开机自启动
systemctl enable cpolar
  • cpolar进行token认证(如果您还没有cpolar账号,请去cpolar官网注册并登录后台获取认证token)
cpolar authtoken NWE3ZTg4OGYtYTJkZC00NDYzLTkyYTEtNGY5OTAzMDNlOTU1
  • 将ssh的监听端口映射出去
cpolar tcp 8022
  • 开启ssh服务

切换到另一个窗口

sshd -d

或者

sshd

下面这个断开会自动重启

使用pc端连接android 端termux(公网连接)

  • 获取域名和端口

在线隧道

隧道名称 URL 地区 本地地址 创建时间
default tcp://23.tcp.cpolar.top:14118 cn_top tcp://127.0.0.1:8022 2024-06-24 22:03:20 +0800 CST
default tcp://7.tcp.cpolar.top:13661 cn_top tcp://127.0.0.1:8022 2024-06-25 01:47:14 +0800 CST
  • 使用ssh连接
ssh u0_a79@7.tcp.cpolar.top -p 13661

termux和一般的linux不同,其实是不需要使用用户名的

ssh 7.tcp.cpolar.top -p 13661
  • 使用scp进行文件传输
scp -P 13661 u0_a79@7.tcp.cpolar.top:/sdcard/hello.sh .

小技巧

避免Termux陷入后台停止运行

以小米手机为例

设置 》 应用设置 》 应用管理 》 Termux 》 省电管理 》 无限制

避免清理内存时杀死后台

以小米手机为例

屏幕右下角上划,调出任务管理,长按Termux,点击锁定图标

posted @ 2024-06-25 02:06  乘舟凉  阅读(6)  评论(0编辑  收藏  举报