Take the 2-minute tour ×
Android Enthusiasts Stack Exchange is a question and answer site for enthusiasts and power users of the Android operating system. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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"
share|improve this answer
    
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. –  Sachin Shekhar 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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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