Getting root rights on Android: how to properly root a smartphone or tablet

There are several ways to get root rights on Android and one of the easiest is to use the Kingo Root application. This program adapts to each device and version of the Android operating system, using their vulnerabilities to hack Android. Read how to install root on Android using Kingo Root on Trashbox.

The best Telegram channel about technology (possibly)

The best Telegram channel about technology (possibly)

What are root rights and why are they needed?

Let’s simulate a situation: a person buys a new smartphone, but it has a lot of pre-installed applications that are not needed and at the same time load the system. At the same time, the new phone freezes somewhat out of the box - you must admit, the situation is not pleasant, and you cannot remove these applications using standard tools. Of course, you can refuse the phone, but in some cases the user approaches the choice consciously, with an understanding of the situation and knowledge of the matter, selects the power of the device.

In such cases, obtaining root rights is required. They allow you to delve deeply into the settings, remove unnecessary built-in applications, and customize the system as comfortably as possible. There are three types of root rights:

  • Full Root - the maximum package, full access to the system, includes the ability to change any file, including system ones.
  • Shell Root - allows you to change any system settings, but does not have access to the system folder.
  • Temporary root – temporary root rights, as a rule, have the same level of access as shell root.

Please note that in some devices, obtaining maximum access to settings is limited at the hardware level.

Run the script as root via ADB Oh! Android

I have created a script to mount partitions and create some things on my Android system. I saved the script as install.sh in Android's /bin folder.

I want to call a script from ADB that itself is called from a batch file on Windows, but it needs to be executed as root.

The first thing I tried was to call the script using

adb shell "su -c sh /bin/script.sh"

But it doesn't work because it gives me shell access (as root) but nothing gets executed. I also tried calling

adb root "sh /bin/script.sh"

But I got the following error

adbd cannot run as root in production builds

Then I tried to write

su -c "command"

For all the commands that need root access in my script, but I have the same problem. When I run the script I only get a root shell and nothing gets executed.

If I use the first solution manually (for example I call adb shell su then my script) it works. However, it's all about automating the process so that the adb shell can be called from another script.

Do you have any idea how I can achieve this?

Thanks to !

This works for me:

Create a myscript.bat and place it in it (note the single quotes around the commands that will be executed as root):

adb shell "su -c 'command1; command2; command3′"

Then run myscript.bat from a DOS shell.

Note: The DOS line continuation character (^) does not work in this situation. In other words, the following doesn't work for me:

adb shell "su -c '^ command1; ^command2; ^command3′"

This results in the error "Syntax error: inexhaustible string"

It works :

adb shell echo command which needs root privileges \| su

If you need to redirect:

adb shell echo 'echo anytext > /data/data/aforbiddenfolder/file' \| su

To "copy" a local file to the android path, requiring root permissions (but alocalfile must not contain ' ):

cat alocalfile | adb shell echo "echo '`cat`' > /data/data/aforbiddenfolder/file" \| su

If you have a better way (even for versions of su that don't have -c ), I'm interested.

This works for me:

adb shell "su -c ./data/local/tcpdump-arm -s 0 -v -w /data/local/appxpress_dump.pcap"

But it doesn't work because it gives me shell access (as root) but nothing gets executed.

How do you know you are granted root privileges? I assume you are trying to execute a script on the device? Has your device been rooted?

You may have to grant execute permissions via chmod to the file.

chmod ugo=rwx /bin/script.sh

It looks like I was using a very simple version of su that didn't accept the -c argument. I copied another su which actually worked. AndyD is absolutely right though, so I'm accepting his answer instead of mine

Rating
( 2 ratings, average 4.5 out of 5 )
Did you like the article? Share with friends:
For any suggestions regarding the site: [email protected]
Для любых предложений по сайту: [email protected]