The adb command on Ubuntu prompts insufficient permissions and lacks udev rules (adb: insufficient permissions for device: missing udev rules? )

In the newly built Ubuntu development environment, use adb to connect to the development board, prompting insufficient permissions and lack of udev rules
(adb: insufficient permissions for device: missing udev rules? user is in the plugdev group).

This problem also affects the use of scrcpy.

$ adb devices
List of devices attached
4a093191        no permissions (missing udev rules? user is in the plugdev group); see [http://developer.android.com/tools/device.html]

$ adb shell
adb: insufficient permissions for device: missing udev rules? user is in the plugdev group
See [http://developer.android.com/tools/device.html] for more information

According to Google's official instructions, the prerequisites for using adb on Ubuntu:
1) The currently logged-in user is in the plugdev group.
(a) View the group of the current user (the current user name is dev):

$ id 
uid=1000(dev) gid=1000(dev) groups=1000(dev),4(adm),27(sudo),30(dip),46(plugdev),116(lpadmin),126(sambashare)

Note: In the plugdev group that the current user has included, you can see 46 (plugdev) in the output above.

(b) If not included, add the current user to the group:

$ sudo usermod -aG plugdev $LOGNAME

Note: Logout or reboot is required for group changes to take effect. And check the confirmation through the id command again.

2) You need to add udev rule to the device.
(1) Use the udev rules of the open source community to install the package.

$ sudo apt-get install android-sdk-platform-tools-common
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  android-sdk-platform-tools-common
0 upgraded, 1 newly installed, 0 to remove and 484 not upgraded.
Need to get 12.2 kB of archives.
After this operation, 50.2 kB of additional disk space will be used.
Get:1 http://mirrors.aliyun.com/ubuntu bionic-security/universe amd64 android-sdk-platform-tools-common all 27.0.0+10~18.04.2 [12.2 kB]
Fetched 12.2 kB in 0s (70.2 kB/s)                            
Selecting previously unselected package android-sdk-platform-tools-common.
(Reading database ... 174139 files and directories currently installed.)
Preparing to unpack .../android-sdk-platform-tools-common_27.0.0+10~18.04.2_all.deb ...
Unpacking android-sdk-platform-tools-common (27.0.0+10~18.04.2) ...
Setting up android-sdk-platform-tools-common (27.0.0+10~18.04.2) ...

After the operation is completed (note the steps that need to be logged out or restarted, you can restart the system once after the operation is safe), use the adb command again to connect to the development board normally.

(2) Manually create a rule file.
Create a dev rule file: /etc/udev/rules.d/51-android.rules (requires sudo), the content is as follows:

$ cat /etc/udev/rules.d/51-android.rules 
SUBSYSTEM=="usb", MODE="0660", GROUP="plugdev", SYMLINK+="android%n"

After the editing is completed, re-plug the usb cable of the mobile phone or the development board to take effect.
Using the adb command again, there is no prompt message for missing permissions.

$ adb devices
List of devices attached
4a093191        device

Guess you like

Origin blog.csdn.net/yinminsumeng/article/details/128907079