Termux安卓上的Linux開發環境


Termux 使用教程 #1 - Android 手機安裝 Linux

Termux 是一個 An­droid 下的終端模擬器,可以在手機上模擬 Linux 環境。它是一個手機 App,可以從應用商店直接下載安裝,打開就能使用,它提供一個命令行界面,讓用戶與系統交互。它支持 apt 軟件包管理,可以十分方便安裝軟件包,而且完美支持 Python、PHP、Ruby、Go、Nodejs、MySQL 等工具。

隨着智能設備的普及和性能的不斷提升,如今手機、平板等設備的硬件標准已經直逼入門級桌面計算機,使用 Ter­mux 完全可以把手機變成一個強大的小型服務器。

你甚至可以使用 Ter­mux 通過 Nmap、Sqlmap、BB­Scan、sub­Do­mains­Brute、Hy­dra、Router­Sploit 等工具實現端口掃描、注入檢測、子域名爆破、多協議弱口令爆破、路由器漏洞檢測框架多種功能,把手機打造成一個隨身攜帶的滲透神器,成為現實版的艾登・皮爾斯。

1. 安裝

homepage

F-Droid安裝包

Termux 是運行在 Android 上的 terminal。不需要root,運行於內部存儲(不在SD卡上)。

自帶了一個包管理器 pkg ,可以安裝許多現代化的開發和系統維護工具。比如:

  • neovim
  • tmux
  • zsh
  • clang
  • gcc
  • python
  • weechat
  • irssi

注意:在Google和F-Droid上發布的安裝包由於簽名不同,並不能相互替換,尤其是在匹配其插件(如Termux-API)時,可能造成意外的錯誤。

插件列表:

  • API: 用於調用安卓的原生功能,如撥打電話、拍照、GPS定位信息等

    • termux-share
    • termux-open-url
  • Termux:API

    Access Android and Chrome hardware features.

  • Termux:Boot

    Run script(s) when your device boots.

  • Termux:Float

    Run Termux in a floating window.

  • Termux:Styling

    Have color schemes and powerline-ready fonts customize the appearance of the Termux terminal.

  • Termux:Tasker

    An easy way to call Termux executables from Tasker and compatible apps.

  • Termux:Widget

    Start small scriptlets from the home screen.

2. 更新源

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

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

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

然后執行 pkg update ,注意,提示更新系統命令時,選擇 n ,否則會造成系統不穩定!

推薦安裝以下軟件:

pkg install openssh htop tsu proot git nano neofetch python
  • tsu:切換賬戶(root)
  • proot:無root權限執行需要root的命令
  • neofetch:查看系統信息

3. 系統配置

termux-setup-storage  # 獲取對sdcard的讀取權限
pkg install termux-services
pkg install termux-api
termux-wake-lock  # 息屏時保持Termux后台運行(否則cpu嚴重降速甚至ssh卡斷)

4. 配置ssh

pkg install openssh

安裝好之后,我們需要手工啟動: sshd

需要指出的是, sshd 監聽的是8022端口而不是22號端口,因此可以使用下面命令來驗證ssh服務是否開啟。

ssh localhost -p 8022

若要查看sshd的日志,則可以在Termux上執行

logcat -s 'syslog:*'

為了方便,我們可以配置一下ssh client的配置文件,將下面內容加入到 ~/.ssh/config 文件中:

Host termux
User u0_a171
HostName 192.168.31.145
Port 8022

這樣只需要執行 ssh termux 就能登陸termx了。

5. Python庫的安裝

  • lxml:

    pkg install libxml2 libxslt && pip install lxml

    經測試,在0.73版本下,安裝報錯:

    fatal error: 'iconv.h' file not found

    解決方案:

    pkg install libiconv

  • Pillow:

    pkg install libjpeg-turbo && pip install pillow

    經驗證,還需要手動安裝 zlib: pkg install zlib

  • numpy:

    pip install numpy

  • pandas:

    最新版本失敗,但 pip install pandas==1.0.5 成功

6. 定制常用按鍵

國光blog: Termux高級終端安裝使用配置教程

在 Termux v0.66 的版本之后我們可以通過 ~/.termux/termux.properties 文件來定制我們的常用功能按鍵,默認是不存在這個文件的,我們得自己配置創建一下這個文件。

下面做嘗試簡單配置一下這個文件:

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

7. Termux:API

homepage

In Google Play Store, besides installing the Termux app, also install "Termux:API" app. This solves the hanging issue described below on Android 7.

To use Termux:API you also need to install the termux-api package.

pkg install termux-api

Current API implementations:

  • termux-battery-status

    Get the status of the device battery.

  • termux-brightness

    Set the screen brightness between 0 and 255.

  • termux-call-log

    List call log history.

  • termux-camera-info

    Get information about device camera(s).

  • termux-camera-photo

    Take a photo and save it to a file in JPEG format.

  • termux-clipboard-get

    Get the system clipboard text.

  • termux-clipboard-set

    Set the system clipboard text.

  • termux-contact-list

    List all contacts.

  • termux-dialog

    Show a text entry dialog.

  • termux-download

    Download a resource using the system download manager.

  • termux-fingerprint

    Use fingerprint sensor on device to check for authentication.

  • termux-infrared-frequencies

    Query the infrared transmitter's supported carrier frequencies.

  • termux-infrared-transmit

    Transmit an infrared pattern.

  • termux-job-scheduler

    Schedule a Termux script to run later, or periodically.

  • termux-location

    Get the device location.

  • termux-media-player

    Play media files.

  • termux-media-scan

    MediaScanner interface, make file changes visible to Android Gallery

  • termux-microphone-record

    Recording using microphone on your device.

  • termux-notification

    Display a system notification.

  • termux-notification-remove

    Remove a notification previously shown with termux-notification --id.

  • termux-sensor

    Get information about types of sensors as well as live data.

  • termux-share

    Share a file specified as argument or the text received on stdin.

  • termux-sms-list

    List SMS messages.

  • termux-sms-send

    Send a SMS message to the specified recipient number(s).

  • termux-storage-get

    Request a file from the system and output it to the specified file.

  • termux-telephony-call

    Call a telephony number.

  • termux-telephony-cellinfo

    Get information about all observed cell information from all radios on the device including the primary and neighboring cells.

  • termux-telephony-deviceinfo

    Get information about the telephony device.

  • termux-toast

    Show a transient popup notification.

  • termux-torch

    Toggle LED Torch on device.

  • termux-tts-engines

    Get information about the available text-to-speech engines.

  • termux-tts-speak

    Speak text with a system text-to-speech engine.

  • termux-usb

    List or access USB devices.

  • termux-vibrate

    Vibrate the device.

  • termux-volume

    Change volume of audio stream.

  • termux-wallpaper

    Change wallpaper on your device.

  • termux-wifi-connectioninfo

    Get information about the current wifi connection.

  • termux-wifi-enable

    Toggle Wi-Fi On/Off.

  • termux-wifi-scaninfo

    Get information about the last wifi scan.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM