On LineageOS 23.2, how to use `adb`, without having to plug a USB cable or use Wi-Fi, thanks to Magisk `root`? Note that I am aware that Magisk `root` gives me equivalent `shell` access.
1:53pm

On LineageOS 23.2 (or any Android device with Magisk root), you can enable ADB over TCP/IP without a USB cable or Wi-Fi by using the adbd daemon directly via a root shell. This method leverages the fact that Magisk provides root access, allowing you to start the ADB daemon in TCP mode manually.

Here’s how to do it:


1. Start adbd in TCP Mode via Root Shell

Run the following commands in a root shell (e.g., via Termux with su, or directly in adbd if already connected via USB once):

bash
su
setprop service.adb.tcp.port 5555
stop adbd
start adbd
  • This binds adbd to port 5555 on all network interfaces (including local loopback and LAN).
  • Replace 5555 with your preferred port if needed.

2. Connect from Your Computer

On your computer, run:

bash
adb connect <device-ip>:5555
  • Replace <device-ip> with your device’s local IP address (e.g., 192.168.1.100).
  • If you’re on the same machine (e.g., using Termux), you can also use adb connect localhost:5555.

3. Verify the Connection

Check if the device is listed:

bash
adb devices

You should see your device with the IP:port.


4. (Optional) Persist Across Reboots

To make this persistent, create a Magisk module or a root script (e.g., in /data/adb/post-fs-data.d/) to run the above commands at boot.

Example Magisk Module:

  1. Create a folder structure:
    text
    /sdcard/Download/adb-tcp/
    ├── customize.sh
    └── post-fs-data.sh
  2. In post-fs-data.sh, add:
    bash
    #!/system/bin/sh
    setprop service.adb.tcp.port 5555
    stop adbd
    start adbd
  3. Zip the folder, flash it in Magisk, and reboot.

5. Security Notes

  • Firewall/Network: Ensure your device’s IP is reachable from your computer (same LAN or VPN).
  • Port Conflicts: Avoid ports already in use (e.g., 5555 is common for ADB, but check with netstat -tuln).
  • Root Access: This requires Magisk’s su access. If you lose root, the daemon will revert to USB-only mode.

Why This Works

  • setprop service.adb.tcp.port forces adbd to listen on TCP.
  • stop adbd && start adbd restarts the daemon with the new settings.
  • No USB or Wi-Fi ADB pairing is needed—just root and network connectivity.

Alternative: If you have Termux, you can also run adb commands directly from the device itself (e.g., adb shell from Termux to another device).

1:53pm

This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.