Home > Back-end >  How to trust adb through SSH in Android
How to trust adb through SSH in Android

Time:04-28

I have a rooted pixel 3 device with magisk installed connected to a mac. I want to work on the device through the mac while connected remotely. Sometimes, I need to restart the android device - when I do, it sometimes stops trusting the mac computer it's connected to.

I've read about disabling dm-verity to always trust the computer, but I'd like to avoid these kinds of solutions - they're insecure, complicated, and risk compromising the device.

Instead, I debugged the android device - I saw that whenever I give trust to the mac it's connected to, two files are generated:

/data/misc/adb/adb_keys
/data/misc/adb/adb_temp_keys.xml

Both of which contain the public adb key of the mac device, which can be found in

~/.android/adbkey.pub

What I tried to do is connect to the android via SSH, and when I lose trust I can push the files from the mac to the android by using scp:

scp -P2222 ~/.android/adbkey.pub user@ip:/sdcard/test
ssh ...
su # using magisk
cp /sdcard/test/adbkey.pub /data/misc/adb/adb_keys
cp /data/misc/adb/adb_keys /data/misc/adb/adb_keys.xml # with some format changes
reboot

I hoped that would get the android device to trust the mac device, but when I run adb-devices, it's still unauthorized.

I've tried restarting adbd on android as well, hoping it would relook the files to authorize the mac, but that didn't work either.

Does anyone know what I'm doing wrong, or how can this be achieved?

CodePudding user response:

I authorized the phone on the mac with persistence ticked, copied the files in /data/misc/adb to a tmp folder, and then when it goes unauthorized I can reconnect via SSH and copy the files back, then restart the adb server on the PC (adb kill-server, adb start-server).

  • Related