4

My phone is rooted CM7 and Superuser.apk has Connectbot in the allowed list. Titanium backup reports that it has root access, to prove that I actually have root working. I seem to remember being able to run commands in Connectbot as root in the past.

But now, I go into Connectbot → Local, and try to run a command using sudo, and it just says "permission denied". No pop-up or anything. Same for the Terminal Emulator app. How do I run commands as root?

8

The su binary works just like it does on Linux; it runs all commands that follow as root until you type exit (or terminate the process, etc.). sudo <command> essentially does:

su
<command>
exit

Android doesn't normally include sudo, so If you wish to launch commands like you would with sudo, the syntax is as follows:

su -c "[command_1;command_2;...;command_N]"

For example, to get a list of installed packages in "root" mode, you can either do

$ su
# pm list packages
# ........ <listing of packages scrolls down> ......
# exit

or

$ su -c "pm list packages;exit"
  • Oh. If I use su by itself, it works. Connectbot is granted superuser permissions and then I can do stuff as root. Does sudo ever work, then? – endolith Mar 26 '12 at 15:06
  • 4
    Linux also have su binary.. so, don't say su as android equivalent of sudo. – Android Quesito Mar 26 '12 at 16:02
  • 1
    sudo isn't installed on Android by default; sudo was written to give people the ability to access certain commands (via configuration) instead of using su to log in as root all the time. su is the more important command when you don't have uid 0 at all on your device. – Broam Mar 26 '12 at 16:54
  • 1
    @SachinShekhar Feel free to correct my answer with proper verbiage. – Chahk Mar 26 '12 at 17:23
  • 1
    wow! I didn't know -c was the tricky option to use. I just kept trying, say, "su logcat" and it never worked. – asgs Sep 8 '14 at 3:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.