I am searching for the equivalent Linux command of following Android adb shell command:
%ANDROID%\platform-tools\adb.exe shell ^
/system/bin/chmod 0777 /data/local/asl-native
This will be used to give the read and write permissions for a particular directory or file.
I have tried with the following Linux commands:
/system/bin/chmod u+rw /data/local/filename
However, it appears the file is not given permissions.
Most Android systems do not let you run as super user (i.e. root) and without that privilege, you cannot make this work.
You can read more bout how file storage works on Android here.
Related
I'm trying to modify the hosts file on my android phone and I am using adb for this on Ubuntu 20.04 to pull the file, modify it and push it back as suggested here. I was able to pull the file but when I try to push it I get an error
adb: error: failed to copy 'Documents/hosts' to '/system/etc/hosts': remote couldn't create file: Read-only file system
One suggestion seems to be to run adb remount or adb shell mount -o rw,remount /system (I'm not sure if these meant to be run on the android device itself) and this doesn't work for me, I get
/system/bin/sh: /system/bin/remount: inaccessible or not found
To this, there seems to be a suggestion to run adb root which returns adbd cannot run as root in production builds. Now I'm not sure how to proceed. There are some threads online saying what to do about this but I feel this is way above my head already. I just want to push the hosts file back to the phone. Is there a simple way to do this?
Do I actually need to root my phone to run a program that prints hello world?
I am trying to run a binary file after I have cross compiled it.
I get permission denied when I push the file into /data/local/tmp directory.
Any ideas where I should push it so that it can run? If possible?
Or do I need to try it on Terminal Emulator?
No, you don't need to have root permissions to run executable on Android.
Most likely, after pushing file to /data/local/tmp, it have no required permissions - that's why you got "permission denied". Do it as following:
adb push /path/to/executable /data/local/tmp
adb shell chmod 0755 /data/local/tmp/executable
adb shell 'cd /data/local/tmp && ./executable'
It works for me.
Do I actually need to root my phone to run a program that prints hello world?
No.
I get permission denied when I push the file into /data/local/tmp directory.
Perform a chmod a+x after you push it. I seem to recall the Android runtime does not understand octal. (Or maybe its the other way around based on #crystax's answer).
I have an Android phone that has only su binary installed and it works, meaning I can adb shell into the phone and run an 'su' command and I will be root.
When I try to run a command via code, it doesn't seem to work no matter which way I try to run it. I've tried many different variants of the following command.
Runtime.getRuntime().exec("su -c ps");
When I run this command on another rooted phone with a Superuser.apk or SuperSU.apk app installed, I get a dialog asking if I want to allow it to run with root permissions. When the apks are not there, it never asks and the command never works.
I've tried installing the apks on the first phone but they don't seem to do anything. So, as the original question asks --> Is there any way to run the elevated command from within the app without the SU apps installed?
It might be because you need to pass the commands to su as parameters like this:
su -c 'ls -l'
Or you might need to specify the full path to su, but I don't see why it wouldn't work the way you have it:
Runtime.exec("/system/bin/su -c ps")Or maybeRuntime.exec("/system/bin/su -c \'ps\'")
Try checking the output of this command too: System.getenv("PATH")
Another variant could be Runtime.exec("su -c \'ls -s \'")
Make sure you don't forget to escape the single quotes as they are part of the actual String.
Thats the way that I've found works most consistently, and it has also worked on devices that don't have Superuser or SuperSU installed, as those apps only listen for the Broadcast that is sent out when an application tries to run a command as root. #Boardy SuperSU and Superuser intercept the broadcast and so act as a middle man between the app and root privileges, but its not necessary for a rooted device. It IS necessary if you want to have more control over the applications that are running commands as root, but even then it still only limits you to deciding which applications, not which commands, are given root privileges.
Also, you might wanna take a look at RootTools and more specifically, the RootTools.isAccessGiven() command, which requests root privileges for your app.
Source: Launch a script as root through ADB
Not all versions of an 'su' for Android will accept a command to execute from the command line parameters.
Where they do not, you will need to let 'su' launch a privileged shell, obtain its input file descriptor, and pipe command(s) into that. This has been covered numerous times here on Stackoverflow.
I believe you would need to have the SU apps installed as they are what provide the user the question as to whether the app should be allowed to run as root or not.
You should be able to do this.
try :
adb root shell ls -l
i am not able to run shell scripts from my application.only "ls -l" and echo commands respond.rest dont seem to do anything.not even "touch" command works.i tried creating a file in sdcard using touch command in my script..only the echo command worked.my shell script is in sdcard too
The sdcard is mounted with noexec. You will have to copy the scripts to the app's local data drive to execute.
You should be able to see the mounted permissions of all file-systems by logging into the phone (adb shell or whatever else) and typing mount
The rest of the commands like "cd" etc doesnot work in Android as it encounters lot of permission issues.
So the best solution is to trigger "script manager" or "terminal emulator" apps already available through your app.
I want to run hello world written on C++ and compiled with Android toolchain 9, but I faced with issue: by default I have no permissions to launch it and I can't change permissions using chmod`.
I used Android 2.3.3 - Api Level 10
Application was compiled by cross compiler for API level 9
Procedure:
Compile application:
~/toolchain_andr9/bin/ arm-linux-androideabi-g++ helloworld.cpp
Then send application to SDCARD on the emulator:
>adb push a.out /mnt/sdcard
then go to SHELL and try to run a.out:
>adb shell
>
>/mnt/sdcard/a.out
And result is:
>`/mnt/sdcard/a.out: permission denied`
command ls -l shows rights for a.out:
>`----rwxr-x system sdcard_rw 863656 2012-04-12 22:42 a.out`
I tried to change permissions:
>chmod 777 /mnt/sdcard/a.out
But rights don't change:
>`----rwxr-x system sdcard_rw 863656 2012-04-12 22:42 a.out`
I think I have left some important thing using android.
Could anybody help me and give me a way how to run application in `Android SHELL?
Thanks a lot.
P.S. sorry for my English =)
By default, the SD card is mounted with option noexec, that disallows the execution of any file on the card, no matter what it's permissions(even -rwxrwxrwx), so you need to move the file to another location and then execute it.
The easiest is to move the file to /data/local/tmp/ and execute it using the full path (usual POSIX PATH semantics).
> adb push a.out /data/local/tmp/a.out
> adb shell
> chmod 755 /data/local/tmp/a.out
> /data/local/tmp/a.out
This does not require root access and survives reboot.
If you have rooted your phone you can do a mount -o remount,rw /mnt/sdcard and it should run.
I've tried it on my Android.