I am on Ubuntu 12.04. And I need to use 'adb shell' to connect to my device on linux:
I get Insufficient permission when running 'adb shell'as myself.
But when I run it as 'root', it works.
How can I fix 'adb shell' so that I don' need to run it as root everytime?
I guess, the problem and solution are the same as in question "adb devices command not working".
In short: you must inform Ubuntu that android device, connected to USB can be used by unprivileged users (that's forbidden by default).
That's even decribed in official Android Developer's Guide: Configuring USB Access, but I prefer a bit simplier 51-android.rules file.
Can You try changing the owner of the file adb ?
sudo chown <usergroup>.<username> adb
This is may work for you!
Related
I use ADB tool and I want to install apk on my emulator. So I use this command
adb install /home/jody/myexample.apk
and I got this error
2841 KB/s (242867 bytes in 0.083s)
pkg: apk
ver: /data/local/tmp/concolicexample.apk
Failure [INSTALL_FAILED_INVALID_URI]
I search this error and from https://mobiledevstories.wordpress.com/2013/06/03/android-adb-install_failed_invalid_uri/ I found out I should The solution is to change permissions to directory but the problem is I don't know where is /data/local/tmp and where should I change permissions?
I should mention that I use genymotion emulator on Linux.
please help me. Sorry if this problem is really primitive. I just begin to use adb.
There are more people with your problem here:
Cannot install package on rooted device : INSTALL_FAILED_INVALID_URI
I think that your device needs to be rooted for this to work, or you won't have sufficient rights. I don't have a rooted device here so don't remember if all steps are necessary:
So the /data/local/ directory is on the Android device, so using adb you need to access the device.
1) adb remount (This might not be necessary, this gives you more access rights to the device)
2) adb shell <- opens a shell on the device instead of your computer.
3) chmod 777 /data/local/
4) chmod 777 /data/local/tmp/
Hopefully it works for you!
I rooted my unlocked Galaxy S3 (SGH-T999)
Now, I'm trying to run adb root from Windows Command Prompt, however, I'm getting adbd cannot run as root in production builds error. So, the very first thing I checked was whether my phone was really rooted?
So I tried the following:
Open Command prompt
$adb devices // lists my device
$adb shell //goes to shell
$su // opens a 'SuperSu' prompt on my phone and I 'Grant' permission
# // Before following the rooting instructions, I was getting 'no su command found' in the previous step. So, I believe my phone is ROOTED. **Correct me if I'm wrong.**
However, when I do adb root, I get adbd cannot run as root in production builds error.
So, I thought, I might have to do some additional stuff beyond what I did above. I tried all the solutions in the following SO questions:
Launch a script as root through ADB
adb remount permission denied, but able to access super user in shell -- android
Unable to run 'adb root' on a rooted Android phone
None of the above worked for me. All they do is give the ROOT access INSIDE of SHELL. I want adb root to work so that I can execute various adb commands WITHOUT going into shell.
By design adb root command works in development builds only (i.e. eng and userdebug which have ro.debuggable=1 by default). So to enable the adb root command on your otherwise rooted device just add the ro.debuggable=1 line to one of the following files:
/system/build.prop
/system/default.prop
/data/local.prop
If you want adb shell to start as root by default - then add ro.secure=0 as well.
Alternatively you could use modified adbd binary (which does not check for ro.debuggable)
From https://android.googlesource.com/platform/system/core/+/master/adb/daemon/main.cpp
#if defined(ALLOW_ADBD_ROOT)
// The properties that affect `adb root` and `adb unroot` are ro.secure and
// ro.debuggable. In this context the names don't make the expected behavior
// particularly obvious.
//
// ro.debuggable:
// Allowed to become root, but not necessarily the default. Set to 1 on
// eng and userdebug builds.
//
// ro.secure:
// Drop privileges by default. Set to 1 on userdebug and user builds.
In some developer-friendly ROMs you could just enable Root Access in Settings > Developer option > Root access. After that adb root becomes available. Unfortunately it does not work for most stock ROMs on the market.
I ran into this issue when trying to root the emulator, I found out it was because I was running the Nexus 5x emulator which had Google Play on it. Created a different emulator that didn't have google play and adb root will root the device for you. Hope this helps someone.
I use for enter su mode in abd shell
adb shell "su"
I have a rooted Samsung Galaxy Trend Plus (GT-S7580).
Running 'adb root' gives me the same 'adbd cannot run as root in production builds' error.
For devices that have Developer Options -> Root access, choose "ADB only" to provide adb root access to the device (as suggested by NgaNguyenDuy).
Then try to run the command as per the solution at Launch a script as root through ADB.
In my case, I just wanted to run the 'netcfg rndis0 dhcp' command, and I did it this way:
adb shell "su -c netcfg rndis0 dhcp"
Please check whether you are making any mistakes while running it this way.
If it still does not work, check whether you rooted the device correctly.
If still no luck, try installing a custom ROM such as Cyanogen Mod in order for 'adb root' to work.
You need to replace the adbd binary in the boot.img/sbin/ folder to one that is su capable. You will also have to make some default.prop edits too.
Samsung seems to make this more difficult than other vendors. I have some adbd binaries you can try but it will require the knowledge of de-compiling and re-compiling the boot.img with the new binary. Also, if you have a locked bootloader... this is not gonna happen.
Also Chainfire has an app that will grant adbd root permission in the play store: https://play.google.com/store/apps/details?id=eu.chainfire.adbd&hl=en
Lastly, if you are trying to write a windows script with SU permissions you can do this buy using the following command style... However, you will at least need to grant (on the phone) SU permissions the frist time its ran...
adb shell "su -c ls" <-list working directory with su rights.
adb shell "su -c echo anytext > /data/test.file"
These are just some examples. If you state specifically what you are trying to accomplish I may be able to give more specific advice
-scosler
adbd has a compilation flag/option to enable root access: ALLOW_ADBD_ROOT=1.
Up to Android 9: If adbd on your device is compiled without that flag, it will always drop privileges when starting up and thus "adb root" will not help at all.
I had to patch the calls to setuid(), setgid(), setgroups() and the capability drops out of the binary myself to get a permanently rooted adbd on my ebook reader.
With Android 10 this changed; when the phone/tablet is unlocked (ro.boot.verifiedbootstate == "orange"), then adb root mode is possible in any case.
If you really need to have ADB running as root, the quickest and easiest way is to install Android Custom ROMs and the most popular is CyanogenMod for it has the Root Access options in developer options menu where you can choose to give root access to apps and ADB. I used CM before but since it wasn't developed anymore, I tried looking for some solutions out there. Although CyanogenMod is still a good alternative because it does not have bloatware.
One alternative I found out from a friend is using adbd insecure app which you could try from here: https://forum.xda-developers.com/showthread.php?t=1687590. In my case, it works perferct with an Android custom kernel, but not with the Android stock ROM (vanilla android only). You may try other alternatives too like modifying boot.img of the Android ROM.
in my case, ( device is rooted )
linux$ adb shell # in linux shell
mobile$ su root #=> notice the $ will become #
mobile# whoami #=> root
if you installed "adb root" module in Magisk, you still have to manually switch to root by su root, otherwise, it just LOOKS LIKE you are root, but actually you are NOT root.
I have a Samsung Galaxy Tab S2 running Android 7.0.
Here's how I rooted it today:
Root the device using Odin
Read Alex P.'s answer in this thread regarding editing system\build.prop file.
download onto your tablet: v1.3.9 System Tools Android: All-In-One toolbox
run the app; under "System Utilities" confirm your Odin root worked using "Root Check"
in the same app goto "Root Manager" and use the "Build.prop editor" to effect the changes in the system\build.prop (as specified by Alex P.).
Final Confirmation:
C:\Android\sdk\platform-tools>adb shell
gts28vewifi:/ $ whoami
shell
gts28vewifi:/ $ su
gts28vewifi:/ # su root
gts28vewifi:/ # whoami
root
Upvote Alex P.'s answer.
Further info
and here
and here too
Root Access in Windows Command: adb shell su
Root Access in MacOS Command: ./adb shell su
we have android + linux m/c, we log in into linux shell and boot the machine in android GUI.
now we have the some script that is running on the same machine through linux shell. In that case when the script hangs we need to restart android machine. but it result into restarting the linux machine too. as they are on same machine. so i need the way to restart the android so it comes out of hang state and control remains on the script that is running through the linux shell.
so is there any adb or linux command that work for me?
Have you tried simply 'reboot' with adb?
adb reboot
Also you can run complete shell scripts (e.g. to reboot your emulator) via adb:
adb shell <command>
The official docs can be found here.
You can reboot the device by sending the following broadcast:
$ adb shell am broadcast -a android.intent.action.BOOT_COMPLETED
adb reboot should not reboot your linux box.
But in any case, you can redirect the command to a specific adb device using adb -s <device_id> command , where
Device ID can be obtained from the command adb devices
command in this case is reboot
I think the only way to do this is to run another machine in parallel and use that machine to issue commands to your android box similar to how you would with a phone. If you have issues with the IP changing you can reserve an ip on your router and have the machine grab that one instead of asking the routers DHCP for one. This way you can ping the machine and figure out if it's done rebooting to continue the script.
Is there any way to make a phone whose status is offline to online without replug the usb line?
Just copy an paste in notepad with a .bat extension.
Before that make sure your adb.exe is included in system path or alternatively replace the 'adb' with path to adb.exe, For example:
C:\adt-bundle-windows-x86_64-20131030\sdk\platform-tools\adb kill-server
#echo off
adb kill-server
adb start-server
adb devices
cls
echo "Android Debug Bridge Restated!!!"
pause
Disable and enable again USB debugging on the phone. Works most of the time. You can also try restarting the adb server on the desktop machine.
There's an 'adb reconnect' subcommand I hadn't noticed before today: it might only be in the newer versions of adb.
There's also a device-side version, but I don't quite see how the local machine can tell the device to do that without already being connected, so perhaps that's something you can execute in a device-side shell.
I'm running Ubuntu 10.10 64 bit. I have ia32-libs installed along with Android Debug Bridge version 1.0.26.
My problem(s):
adb devices >>> ???????????? no permissions
sudo adb devices >>>> sudo: adb: command not found
adb shell >>> error: insufficient permissions for device
I guess these are all related. Here's the relevant info.
$ echo $PATH
/home/me/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/opt/android-sdk-linux_x86/tools:/opt/android-sdk-linux_x86/platform-tools
$ which adb
/opt/android-sdk-linux_x86/platform-tools/adb
$ adb devices
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
List of devices attached
???????????? no permissions
$ sudo adb devices
sudo: adb: command not found
$ adb shell
error: insufficient permissions for device
I get the same results with a rooted Moto Droid running CM6.1 and a rooted G-Tab running a CM7-based ROM.
I have reviewed the following related posts:
http://forum.xda-developers.com/archive/index.php/t-522827.html
http://ubuntuforums.org/archive/index.php/t-1164359.html
adb command not found in linux environment
I tried most (not all) of the suggestions and I have not been able to resolve my issue. The things I didn't try seemed inappropriate. I would appreciate a few more tips and I'll keep troubleshooting.
One thing I didn't try was editing /etc/udev/rules.d/70-android.rules. Is that likely to be the issue? I can't see how that would cause "sudo: adb: command not found". Maybe my problems are not all related. Anyway, at this point I think I need some input from other people because I don't believe I have a path problem or the other common problems discussed in those other posts.
EDIT: SOLVED thanks to EboMike and RivieraKid. This was actually two different problems:
Item #2 above (sudo: adb: command not found) was solved by making a symlink as follows:
$ sudo ln -s /opt/android-sdk-linux_x86/platform-tools/adb /usr/local/sbin/adb
That allowed me to then do as EboMike suggested and use this solution. Doing that was required for my Moto Droid. (Running adb as sudo was not required for my Viewsonic G-Tablet, however.)
My other two items were resolved by implementing the udev rule as RivieraKid suggested (from this link).
One thing I didn't try was editing
/etc/udev/rules.d/70-android.rules. Is
that likely to be the issue?
Any particular reason why you didn't do that? To answer the question - YES! The udev rules are what informs Ubuntu what your device is and allows user-space tools to therefore access it.
You will not be able to use adb without correctly following the instructions.
With that in mind however, you don't say what version of Ubuntu you're using but I had issues with 10.10 - let me know if you need me to post the contents of my rules file.
Don't worry about running adb via sudo, you don't need it. The MODE="0666" from the udev rule allows you to access the device as any user.
EDIT:
Don't forget to reload the rules:
sudo udevadm control --reload-rules
EDIT #2:
As #Jesse Glick correctly points out, if adb is already running in daemon mode, you'll also need to restart it for this to work:
sudo adb kill-server
I've used sudo here, since that will guarantee that adb will be killed , and it's the officially supported method to stop the server. It will be automatically restarted the next time adb is used, but this time with the correct environment.
You need to restart the adb server as root. See here.
On my Gentoo/Funtoo linux system I am having similar problems:
I gotting always not the correct device description and insufficient permissions:
# sudo ./adb devices
List of devices attached
???????????? no permissions
# ./adb usb
error: insufficient permissions for device
For me helps the howto from Google.
In my case I needed to add the udev rule:
# cat /etc/udev/rules.d/51-android.rules
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", MODE="0666", GROUP="plugdev"
and setting up the filesystem rights
# chmod a+r /etc/udev/rules.d/51-android.rules
After replugging my smartphone the access to the phone was successful, it also appears now in Eclipse' Android Device Chooser:
# sudo ./adb devices
List of devices attached
3XXXXXXXXXXXXXC device
# sudo ./adb usb
restarting in USB mode
You also have to check the membership of your user to the plugdev-group.
Every answer I've read indicates the SUBSYSTEM=="usb". However, my (perhaps ancient) udev needed this to be changed to DRIVER=="usb". At last I can run the adb server as a non-root user... yay.
It can be instructive to look at the output of udevmonitor --env, followed by the output of
udevinfo -a -p <DEVICE_PATH_AS_REPORTED_BY-udevmonitor>
Please note that IDEs like IntelliJ IDEA tend to start their own adb-server.
Even manually killing the server and running an new instance with sudo won't help here until you make your IDE kill the server itself.
restarting the adb server as root worked for me. see:
derek#zoe:~/Downloads$ adb sideload angler-ota-mtc20f-5a1e93e9.zip
loading: 'angler-ota-mtc20f-5a1e93e9.zip'
error: insufficient permissions for device
derek#zoe:~/Downloads$ adb devices
List of devices attached
XXXXXXXXXXXXXXXX no permissions
derek#zoe:~/Downloads$ adb kill-server
derek#zoe:~/Downloads$ sudo adb start-server
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
derek#zoe:~/Downloads$ adb devices
List of devices attached
XXXXXXXXXXXXXXXX sideload
I fixed this issue on my debian GNU/Linux system by overiding system rules that way :
mv /etc/udev/rules.d/51-android.rules /etc/udev/rules.d/99-android.rules
I used contents from files linked at :
http://rootzwiki.com/topic/258-udev-rules-for-any-device-no-more-starting-adb-with-sudo/
HTC One m7 running fresh Cyanogenmod 11.
Phone is connected USB and tethering my data connection.
Then I get this surprise:
cinder#ultrabook:~/temp/htc_m7/2015-11-11$ adb shell
error: insufficient permissions for device
cinder#ultrabook:~/temp/htc_m7/2015-11-11$ adb devices
List of devices attached
???????????? no permissions
SOLUTION: Turn tethering OFF on phone.
cinder#ultrabook:~/temp/htc_m7/2015-11-11$ adb devices
List of devices attached
HT36AW908858 device
I just got the same situation, Factory data reset worked well for me.