1

adb pull and adb push can be used to transfer files from and to the device via the ADB connection.

However, even on a rooted device, these commands seem to operate with user permissions. I can access anything on /sdcard, but when I try to push to, say, /data, the operation fails due to lack of permissions.

Of course, I can push the file to a different location, then adb shell into the device, run su to become root, and then copy the file to its final destination – but that is a kludgy workaround, not a real solution.

Also, I can install an SSH server on the device which runs as root and use SSH to copy the files over, but I am wondering if ADB offers something similar natively.

Is there any way I can get adb push/adb pull to operate with root privileges on the device?

5
  • 1
    The reason for this behavior is that adbd is by default compiled in "secure mode" which means it is started with root permissions but after start-up it drops it's root permissions. So the only way to change this is to replace or modify the adbd binary included in the installed ROM.
    – Robert
    Feb 5 at 13:46
  • I see that adbd runs as a non-privileged user, as does any process it spawns. That includes shell sessions – however, if enabled on the device, I can then run su from that shell session to obtain root privileges. So you’re saying that adbd does not have any built-in functionality for doing that and/or the ADB wire protocol lacks the means to specify whether an operation is to be carried out in privileged mode?
    – user149408
    Feb 5 at 13:51
  • Yes, adbd runs as non-privileged user, but it is started with root permissions (which is then dropped after start-up). ssh is running always with root permissions and if a user connects the shell process is executed as the user which has logged-in. adbd can not do somethin similar because it has dropped root permissions after start-up and also adbd is not designed to run a shell or a file-transfer session as a different user, so adb always has the permissions adbd runs with.
    – Robert
    Feb 5 at 14:14
  • 4
    If adb root works on your device, it'll make adbd run with UID 0. Feb 5 at 14:47
  • you can use exec-out or exec-in with su -c flag, similar to this. or push files to /data/local/tmp and then move them
    – alecxs
    Feb 5 at 23:45

0

You must log in to answer this question.

Browse other questions tagged .