[General Questions and Answers] xXx yYy:
@Jeremycummings

Here the guide anounced

#########################################################################

Preface:

1. su (shorthand for switch user) is a Linux program designed to switch users or run commands with elevated privileges.

2. Termux is a powerful Android terminal emulation with an extensive Linux package collection - for devices with ARM or ARM64 processors only!

Installing Termux does not require root access on your Android device. Termux is designed to be a Linux environment for non-rooted devices, allowing you to use a variety of command-line tools and utilities.

Take note that Termux installation will allocate >= 2 GB disk space.

3. Here are some common use cases for su in Termux:

System Maintenance and Configuration:

Modify system files or configurations that require root access.

Install system-level packages or utilities.

App Development and Testing:

Debugging apps that need root permissions.

Testing root-related functionality within your app.

Network Diagnostics and Troubleshooting:

Use tools like ping, traceroute, or netstat with root privileges.

Investigate network issues more thoroughly.

Security Auditing:

Inspect system logs, analyze security events, or check for vulnerabilities.

Run security-related tools that require root access.

Customization and Theming:

Modify system fonts, themes, or icons.

Customize your device’s appearance.

A:

Installing Termux

Download the (at the time of this writing latest) Termux package version 0.118.0 (118) from https://f-droid.org/en/packages/com.termux/

and install it.

Note: The installation creates a "bin" subfolder in directory /data/data/com.termux/files/usr, which you can place any binaries (or) executables in that folder that can be called from any where in Termux, so also the su binary.

B:

Setup Termux

1.Grant Termux local storage access

By default, Termux does not have access to your internal and sd card storage. You need to manually set up the permission. Run this command in Termux

termux-setup-storage

After you run the above command, a pop-up box will appear asking you for permission to access the local storage. Tap Allow. Unfortunately, Termux currently doesn't offer a built-in way to automatically tap "Allow" on the storage permission pop-up.

2. Update and/or upgrade Termux

Run the following command in Termux to update and/or upgrade Termux:

apt update > /dev/null 2>&1 && apt upgrade -y > /dev/null 2>&1

The process will take some time, so be patient.

3. Install WGET functionality

Run the following command in Termux to add wget functionality

pkg install wget

C:

Adding the SU binary to Termux

1. Create space to hold Toybox (Note: Google merged Toybox into AOSP and began shipping it with Android 6.0 in 2015)

mkdir -p -m 0755 /data/data/com.termux/files/toybox && cd /data/data/com.termux/files/toybox

2. Get device's CPU architecture, download the matching Toybox suite and store it in Termux's /files subfolder

Run following one-liner command in Termux:

sh 'ARCH=$(uname -m) && \ [[ "$ARCH" == "arm64" ]] && TOYBOX_URL="https://landley.net/toybox/bin/toybox-aarch64" || \ "$ARCH" == "arm32" && TOYBOX_URL="https://landley.net/toybox/bin/toybox-armv7l" \ wget $TOYBOX_URL -q'

Let’s break it down:

The ARCH=$(uname -m) command assigns the output of uname -m (which returns the machine architecture) to the ARCH variable.

The script then uses conditional statements to set the TOYBOX_URL variable based on the value of ARCH. If ARCH is equal to “arm64,” it sets the URL to “https://landley.net/toybox/bin/toybox-aarch64”; otherwise, if ARCH is equal to “arm32,” it sets the URL to “https://landley.net/toybox/bin/toybox-armv7l”.

Finally, it downloads the Toybox binary from the determined URL using wget.

3. Extract SU binary from Toybox suite and store it in /data/data/com.termux/files/usr/bin/ subfolder.

Run following one-liner command in Termux:

chmod +x toybox && toybox --extract su && cat su > /data/data/com.termux/files/usr/bin/su && rm -rf /data/data/com.termux/files/toybox

4. Make the SU-binary executable

Run the following command in Termux:

chmod +xs /data/data/com.termux/files/usr/bin/su

D:

Verify the installation of SU binary

To verify that the su binary is installed correctly, run the following command in Termux:

su --version

If you’ll see the version number displayed you successfully have root access on your device. If not, you will receive an error message. Good luck! 😊

E:

Add SU-binary to Android's search PATH thus it's systemwide accessible

mkdir -p -m 0755 /data/data/com.termux/files/suhome
cp /data/data/com.termux/files/usr/bin/su /data/data/com.termux/files/suhome/su
su -c 'export PATH="/data/data/com.termux/files/suhome:$PATH"'

Addendum:

su

usage: su [-lp] [-u UID] [-g GID,...] [-s SHELL] [-c CMD] [USER [COMMAND...]]

Switch user, prompting for password of new user when not run as root.

With one argument, switch to USER and run user's shell from /etc/passwd.

With no arguments, USER is root. If COMMAND line provided after USER,

exec() it as new USER (bypassing shell). If -u or -g specified, first

argument (if any) isn't USER (it's COMMAND).

first argument is USER name to switch to (which must exist).

Non-root users are prompted for new user's password.

-s Shell to use (default is user's shell from /etc/passwd)

-c Command line to pass to -s shell (ala sh -c "CMD")

-l Reset environment as if new login.

-u Switch to UID instead of USER

-g Switch to GID (only root allowed, can be comma separated list)

-p Preserve environment (except for $PATH and $IFS)

#########################################################################

HTH