[ASUS ZenFone 8] bnsmb:
Note

If access to a phone connected via USB already works, you can skip this part of this post.

On most Linux distributions special udev rules are required to access phones connected via USB ports. These udev rules should be automatically added while installing the packages with the Android tools. To check this, search for a file called android something in the directory /etc/udev/rules.d , example:

[ OmniRom 14 Dev - xtrnaw7@t15g /data/develop/android ] $ ls -l /etc/udev/rules.d
total 80
-rw-r--r--. 1 root root 1926 Jan 28 13:10 40-libsane.rules
lrwxrwxrwx. 1 root root 45 May 15 11:39 51-android.rules -> /usr/share/doc/android-tools/51-android.rules
-rw-r--r--. 1 root root 73728 May 15 11:18 51-android.rules:q
-rw-r--r--. 1 root root 1926 Jan 28 13:10 S99-2000S1.rules
[ OmniRom 14 Dev - xtrnaw7@t15g /data/develop/android ] $

If the udev config to access phones via USB is missing, add the udev rules manually, e.g. on Fedora 39 after installing the rpm package with the Android tools (android-tools) this can be done using these commands:

sudo ln -s /usr/share/doc/android-tools/51-android.rules /etc/udev/rules.d

and request the udev daemon to re-load the udev rules:

sudo udevadm control --reload
sudo udevadm trigger

Since the devices for USB devices are created and destroyed dynamically, you must physically disconnect and reconnect the phone to activate the new udev rule.

To check, that your phone is supported by the udev config use these instructions:

Attach your phone via USB and list the attached USB devices to get the Vendor ID for the phone, example (for an ASUS Zenfone 8):

[ OmniRom 14 Dev - xtrnaw7@t15g /data/develop/android ] $ lsusb | grep Zenfone
Bus 003 Device 097: ID 0b05:7770 ASUSTek Computer, Inc. Zenfone 8
[ OmniRom 14 Dev - xtrnaw7@t15g /data/develop/android ] $

The Vendor ID necessary for the udev rule is the first hexadecimal string after ID, in this example 0b05.

Now check, that the Vendor ID for your phone is configured in the udev config file:

[ OmniRom 14 Dev - xtrnaw7@t15g /data/develop/android ] $ grep -i 0b05 /etc/udev/rules.d/51-android.rules
SUBSYSTEM=="usb", ATTR{idVendor}=="0b05", MODE="0666", GROUP="plugdev"
[ OmniRom 14 Dev - xtrnaw7@t15g /data/develop/android ] $

If the config is missing, add it manually and reload the udev config (see above).

Next check, that your userid is member of the group configured in the udev config file (in this example the group is called plugdev):

xtrnaw7@t15g:~$ id
uid=1000(xtrnaw7) gid=1000(xtrnaw7) groups=1000(xtrnaw7),6(disk),10(wheel),967(adbusers),970(vboxusers),1002(tftp),1003(plugdev) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
xtrnaw7@t15g:~$

Add your userid to that group if it's not yet member of the group:

sudo gpasswd -a $(whoami) plugdev

Newly configured groups for a user are only active for new sessions; I therefore recommend restarting the PC after changing the group configuration to ensure that all processes running for this user ID use the new group.

Note

A repository with udev rules for Android devices that claims to support most of the Android phones is available here: https://github.com/M0Rf30/android-udev-rules

The adb daemon

A running adb daemon under Linux is required to access the phone via USB using adb.

If the adb daemon is not running when adb is executed, it is started automatically; example:

[ OmniRom 14 Dev - xtrnaw7@t15g /data/backup/Android/scripts_on_linux ] $ ps -ef | grep -v grep | grep " adb "
[ OmniRom 14 Dev - xtrnaw7@t15g /data/backup/Android/scripts_on_linux ] $

[ OmniRom 14 Dev - xtrnaw7@t15g /data/backup/Android/scripts_on_linux ] $ adb shell uname -a
* daemon not running; starting now at tcp:5037
* daemon started successfully
Linux localhost 5.4.268-qgki-perf-gb2eb9881deaa-dirty #1 SMP PREEMPT Mon Feb 19 18:27:19 EST 2024 aarch64 Toybox
[ OmniRom 14 Dev - xtrnaw7@t15g /data/backup/Android/scripts_on_linux ] $

[ OmniRom 14 Dev - xtrnaw7@t15g /data/backup/Android/scripts_on_linux ] $ ps -ef | grep -v grep | grep " adb "
xtrnaw7 983862 1 0 09:54 ? 00:00:00 adb -L tcp:5037 fork-server server --reply-fd 4
[ OmniRom 14 Dev - xtrnaw7@t15g /data/backup/Android/scripts_on_linux ] $

To start the adb manually, use the adb parameter start-server; for example, to start the adb daemon explicitly as the root user:

[ OmniRom 14 Dev - xtrnaw7@t15g /data/develop/android/scripts_on_linux ] $ sudo adb start-server
* daemon not running; starting now at tcp:5037
* daemon started successfully
[ OmniRom 14 Dev - xtrnaw7@t15g /data/develop/android/scripts_on_linux ]

# check the result

[ OmniRom 14 Dev - xtrnaw7@t15g /data/develop/android/scripts_on_linux ] $ ps -ef | grep -i " adb "
root 1003277 1 0 11:44 ? 00:00:00 adb -L tcp:5037 fork-server server --reply-fd 4
xtrnaw7 1003322 12411 0 11:44 pts/3 00:00:00 grep --color=auto -i adb
[ OmniRom 14 Dev - xtrnaw7@t15g /data/develop/android/scripts_on_linux ] $

The running adb daemon serves all adb requests from all users on the PC, regardless of which user started it, for example:

ums@t15g:~$ ps -ef | grep -v grep | grep " adb "
xtrnaw7 992597 992596 0 10:41 ? 00:00:00 adb -L tcp:5037 fork-server server --reply-fd 4
ums@t15g:~$

ums@t15g:~$ id
uid=1001(ums) gid=1001(ums) groups=1001(ums) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
ums@t15g:~$

ums@t15g:~$ adb shell uname -a
Linux localhost 5.4.268-qgki-perf-gb2eb9881deaa-dirty #1 SMP PREEMPT Mon Feb 19 18:27:19 EST 2024 aarch64 Toybox
ums@t15g:~$

Every user on the PC can kill the adb daemon using the approbiate parameter for the adb command, for example:

[ OmniRom 14 Dev - xtrnaw7@t15g ~ ] $ ps -ef | grep -v grep | grep -i " adb "
root 987419 1 0 10:12 ? 00:00:00 adb -L tcp:5037 fork-server server --reply-fd 4
[ OmniRom 14 Dev - xtrnaw7@t15g ~ ] $

[ OmniRom 14 Dev - xtrnaw7@t15g ~ ] $ id
uid=1000(xtrnaw7) gid=1000(xtrnaw7) groups=1000(xtrnaw7),6(disk),10(wheel),970(vboxusers),1002(tftp) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[ OmniRom 14 Dev - xtrnaw7@t15g ~ ] $

[ OmniRom 14 Dev - xtrnaw7@t15g ~ ] $ adb kill-server
[ OmniRom 14 Dev - xtrnaw7@t15g ~ ] $

[ OmniRom 14 Dev - xtrnaw7@t15g ~ ] $ ps -ef | grep -v grep | grep -i " adb "
[ OmniRom 14 Dev - xtrnaw7@t15g ~ ] $

The connection via adb between the PC and the phone is secured by an SSL key. The on SSL key used for this connection is the file adbkey in the directory .android in the home directory of the user who started the adb daemon on the PC, example:

[ OmniRom 14 Dev - xtrnaw7@t15g /data/backup/Android/scripts_on_linux ] $ ps -ef | grep -v grep | grep " adb "
xtrnaw7 983862 1 0 09:54 ? 00:00:00 adb -L tcp:5037 fork-server server --reply-fd 4
[ OmniRom 14 Dev - xtrnaw7@t15g /data/backup/Android/scripts_on_linux ] $

[ OmniRom 14 Dev - xtrnaw7@t15g /data/backup/Android/scripts_on_linux ] $ grep xtrnaw7 /etc/passwd
xtrnaw7:x:1000:1000:Bernd Schemmer:/home/xtrnaw7:/bin/bash
[ OmniRom 14 Dev - xtrnaw7@t15g /data/backup/Android/scripts_on_linux ] $

[ OmniRom 14 Dev - xtrnaw7@t15g /data/backup/Android/scripts_on_linux ] $ ls -al /home/xtrnaw7/.android/
total 128
drwxr-x---. 4 xtrnaw7 xtrnaw7 4096 Apr 29 17:07 .
drwx------. 66 xtrnaw7 xtrnaw7 12288 May 3 08:52 ..
-rw-------. 1 xtrnaw7 xtrnaw7 1704 Mar 31 2022 adbkey
-rw-r--r--. 1 xtrnaw7 xtrnaw7 722 Apr 2 11:07 adbkey.pub
[ OmniRom 14 Dev - xtrnaw7@t15g /data/backup/Android/scripts_on_linux ] $

The SSL key in the directory ~/.android is created automatically by the adb the first time it is started for this user:

ums@t15g:~$ id
uid=1001(ums) gid=1001(ums) groups=1001(ums) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
ums@t15g:~$

ums@t15g:~$ ls -l $HOME/.android
total 0
ums@t15g:~$

ums@t15g:~$ adb shell uname -a
* daemon not running; starting now at tcp:5037
* daemon started successfully
ums@t15g:~$

ums@t15g:~$
ums@t15g:~$ ls -l $HOME/.android
total 12
-rw-r--r--. 1 ums ums 12 May 3 10:05 adb.5037
-rw-------. 1 ums ums 1704 May 3 10:05 adbkey
-rw-r--r--. 1 ums ums 717 May 3 10:05 adbkey.pub
ums@t15g:~$

The executable openssl can be used to check or view the key (well, the infos printed by openssl for the key are not really useful ...):

openssl rsa -in adbkey -text -noout

On the first connection from a new PC via adb, the phone prints the fingerprint of the SSL key used for the connection and prompts the user for confirmation, for example:

View attachment 6106092

To check the fingerprint of the SSL key on the PC use this command

adb pubkey ${HOME}/.android/adbkey | awk '{ print $1}' | openssl base64 -A -a -d | openssl md5 -c | tr a-z A-Z

Example:

[ OmniRom 14 Dev - xtrnaw7@t15g ~ ] $ adb pubkey ${HOME}/.android/adbkey | awk '{ print $1}' | openssl base64 -A -a -d | openssl md5 -c | tr a-z A-Z
MD5(STDIN)= F9:48:9A:7F:8E:E9:E6:C0:DB:83:C3:53:6D:4A:5C:97
[ OmniRom 14 Dev - xtrnaw7@t15g ~ ] $

(This command is "stolen" from this page: https://joachimschuster.de/posts/debug-on-device-rsa-fingerprint/ )

Notes:

The SSL key is neither protected by a private key nor user-dependent. Therefore, you can just copy the file adbkey to the directory .android in the home directdory of another user on the same or a different PC to enable adb connections for that user. You should therefore take care of the SSL keys.

Update 26.05.2024

For using the sideload feature of the binary twrp from TWRP the adb on the PC must be started by the user root (see How to install an OS image via sideload using the TWRP binary twrp)

With correct udev rules adb sideload also works if the adb was started by a non-root user.

In Fedora 39 (and probably in other Linux distributions also) the package with the Android tool creates a systemd service to start the adb daemon:

[ OmniRom 14 Dev - xtrnaw7@t15g ~ ] $ systemctl status adb
○ adb.service - Android Debug Bridge (adb) service
Loaded: loaded (/usr/lib/systemd/system/adb.service; disabled; preset: disabled)
Drop-In: /usr/lib/systemd/system/service.d
└─10-timeout-abort.conf
Active: inactive (dead) since Fri 2024-05-03 11:02:48 CEST; 6s ago
Duration: 6min 57.269s
Process: 995228 ExecStart=/usr/bin/adb start-server (code=exited, status=0/SUCCESS)
Process: 996171 ExecStop=/usr/bin/adb kill-server (code=exited, status=0/SUCCESS)
Main PID: 995229 (code=exited, status=0/SUCCESS)
CPU: 113ms

May 03 10:55:48 t15g.isbs.de systemd[1]: Starting adb.service - Android Debug Bridge (adb) service...
May 03 10:55:48 t15g.isbs.de adb[995228]: * daemon not running; starting now at tcp:5037
May 03 10:55:51 t15g.isbs.de adb[995228]: * daemon started successfully
May 03 10:55:51 t15g.isbs.de systemd[1]: Started adb.service - Android Debug Bridge (adb) service.
May 03 11:02:48 t15g.isbs.de systemd[1]: Stopping adb.service - Android Debug Bridge (adb) service...
May 03 11:02:48 t15g.isbs.de systemd[1]: adb.service: Deactivated successfully.
May 03 11:02:48 t15g.isbs.de systemd[1]: Stopped adb.service - Android Debug Bridge (adb) service.
[ OmniRom 14 Dev - xtrnaw7@t15g ~ ] $

The service is not enabled by default:

[ OmniRom 14 Dev - xtrnaw7@t15g ~ ] $ systemctl is-enabled adb
disabled
[ OmniRom 14 Dev - xtrnaw7@t15g ~ ] $

The service starts the adb daemon as user root.

To start the adb daemon using the systemd service execute as user root:

systemctl start adb

To automatically start the adb daemon using the systemd service after every reboot execute as user root:

systemctl enable abd

In case you're using the systemd service for the adb daemon be aware that the SSL key used for the connection might not be the key from the directory ${HOME}/.android from the user root:

[ OmniRom 14 Dev - xtrnaw7@t15g ~ ] $ cat /usr/lib/systemd/system/adb.service
# Systemd unit file for adb

[Unit]
Description=Android Debug Bridge (adb) service

[Service]
Type=forking
ExecStart=/usr/bin/adb start-server
ExecStop=/usr/bin/adb kill-server
PrivateTmp=yes
Environment=HOME=/var/lib/adb

[Install]
WantedBy=multi-user.target
[ OmniRom 14 Dev - xtrnaw7@t15g ~ ] $

In this configuration the SSL key used for the adb connection is in the directory /var/lib/adb/.android:

[ OmniRom 14 Dev - xtrnaw7@t15g ~ ] $ sudo ls -al /var/lib/adb/.android/
total 20
drwxr-x---. 2 root root 4096 Apr 29 23:37 .
drwxr-xr-x. 3 root root 4096 Apr 29 23:37 ..
-rw-r--r--. 1 root root 12 May 3 10:55 adb.5037
-rw-------. 1 root root 1704 Apr 29 23:37 adbkey
-rw-r--r--. 1 root root 714 Apr 29 23:37 adbkey.pub
[ OmniRom 14 Dev - xtrnaw7@t15g ~ ] $

On the phone the config files for the adb connections are stored in the directory /data/misc/adb :

ASUS_I006D:/ # id
uid=0(root) gid=0(root) groups=0(root) context=u:r:magisk:s0
ASUS_I006D:/ #

ASUS_I006D:/ # ls -l /data/misc/adb/
total 8
-rw-r----- 1 system shell 722 2024-05-03 11:15 adb_keys
-rw------- 1 system shell 810 2024-05-03 11:15 adb_temp_keys.xml
ASUS_I006D:/ #

To restart the adb on the phone this command can be used on the PC:

adb shell su - -c setprop ctl.restart adbd

The command to reset the USB port on the phone is

svc usb resetUsbPort

e.g.

ASUS_I006D:/ $ svc usb resetUsbPort
Use the default USB port: port0
Reset the USB port: port0
ASUS_I006D:/ $

Note that resetting the USB port does not end existing adb connections to the phone

Access to the phone connected via USB using fastboot

The udev configuration is also required to access a phone connected via USB with fastboot.

In many udev configurations for accessing a phone, the udev connections allow access via adb for non-root users, but not access via fastboot.

In this case, access to the phone via fastboot is only allowed for the root user, so any fastboot command executed by a non-root user must be preceded by "sudo", example:

[ OmniRom 14 Dev - xtrnaw7@t15g /data/develop/android ] $ fastboot devices
no permissions (user xtrnaw7 is not in the plugdev group); see [http://developer.android.com/tools/device.html] fastboot

[ OmniRom 14 Dev - xtrnaw7@t15g /data/develop/android ] $

but

[ OmniRom 14 Dev - xtrnaw7@t15g /data/develop/android ] $ sudo fastboot devices
M6AIB760D0939LX fastboot

[ OmniRom 14 Dev - xtrnaw7@t15g /data/develop/android ] $

If this is the case: Check the udev configuration for your phone; it should be as listed above:

SUBSYSTEM=="usb", ATTR{idVendor}=="0b05", MODE="0666", GROUP="plugdev"

and your userid must be member of the group configured for the USB device (plugdev in this example).

see also:

adb documentation in the Android SDK

adb HowTo on XDA

adb manpage

How to enable access via adb on a new installed OS

How to reset the USB port used to connect an Android_phone

How to enable adb via WiFI

Some hints about EDL mode