I recently found a way to maintain root access on my android device using a dropbear SSH server that I modified to run at boot as root using init.d, a lil scripting magic & some config scripts I made. If you want you can check it out here. Anyways for an experiment I removed the su binary and Superuser.apk from the system. I've managed to get them copied back to the system but I don't know the appropriate permissions for the su binary. If I look in Super User app on another rooted phone and go to update it shows -rwsr -sr-x as the permissions on the binary. How can I set these same permission manually & what do they mean?


For setting file permissions, you can use the chmod command. The permissions shown are basically split in 3 parts, each consisting of 3 chars: a triple for the owner, the group, and for "others". Usually, each triple holds definitions for reading, writing, and executing a file; so rwx means "can read, write, and execute", while r-- would say "can only read".

The resulting 9 chars are usually preceded by another one, giving information of the type of the "file": (d)irectory and (l)ink are the most common examples. Again, if no "special condition" matches, a leading - indicates a "normal file".

Based on that, let's take your input: -rwsr-sr-x obviously describes a "normal file" (starting with -), readable (r) by owner, group, and others, writable by owner only, and executable by "others" ­– while owner and group have a s instead the x for execute. This stands for "suid", elevate the caller to the level of the file owner/group.

Taking advantage of the fact permissions can be set "bit-wise" (x=1,w=2,r=4, suid user=4, group=2), after my long "rant" finally the command which should do the trick:

chmod 6774 su

Should set the permissions your question shows. If I "mis-calculated", you've got all information to re-calculate for yourself now :)

Additional hints from the comments:

Instead of calculating the "bitmask", one can also use symbolic names – as Dan Hulme pointed out, and as explained e.g. on the chmod manpage:

  • defining whom to grant to: (u)ser / (g)roup / (o)thers / (a)ll
  • defining what to grant: (r)ead / (w)rite / e(x)ecute / (s)uid
  • defining whether to (+)grant or (-)revoke

So the following two commands should be similar, provided there haven't been other things granted before:

chmod 6774 su
chmod u+rws g+rs o+rx su

The difference becomes clear in case e.g. before "others" had also write permission: while the first command (using a bitmask) sets the permission explicitly to match the "grants" defined (and thus would remove that write permission), the symbolic one "makes a diff" (in the example, it just adds the permissions specified to whatever was there before, so that write permission would not be removed).

  • You don't need to calculate the numbers for chmod yourself: chmod u+rws g+rs a+rx su will do exactly the right thing, and doesn't require you to count on your fingers. – Dan Hulme Oct 25 '13 at 8:47
  • Sure that it's not chmod u+rws g+rs o+rx su (not "all", but "o"thers, see chmod manpage)? I always mess that up thinking whether was it "owner" or "others", which is why I prefer using the bitwise stuff, except when only changing stuff for group ;) – Izzy Oct 25 '13 at 9:33
  • @DanHulme checking with the manpage again, a+rx would set "rx" for "ugo" (user, group and others). I'm not sure which confuses me more: calculating the bit-set, or interpreting recursing symbols :P – Izzy Oct 25 '13 at 9:40
  • Yes, using a would make the command shorter, but as you've noticed, it makes it a bit harder to see what is going on, so I almost never use a. – Dan Hulme Oct 25 '13 at 9:42
  • @DanHulme I didn't even know about the a symbol. But thanks for kicking me into checking the manpage again :D The a switch can be quite useful sometimes, for things like chmod a+r public_info.txt. – Izzy Oct 25 '13 at 12:47

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.