MagiskSU (su)
su is how apps and shells get root on a Magisk phone. The command itself is a thin client: it asks the Magisk daemon, which checks your Superuser settings and, if root is allowed, starts the shell for you. This page lists every option as the source code parses it and explains what changed in v31.1, the current stable release.
Last updated 6 sourcesHow we check pages
- What su isA link to
magiskNo separate MagiskSU download - Default shell
/system/bin/shChange with-s - Current v31.1No promptsGrant in the Superuser tab first
- Previous v30.7Prompt on first useChoice saved in the Superuser tab
- When refused
Permission deniedExit code 13
Basic use
A working root shell prints uid=0(root) gid=0(root) and context=u:r:magisk:s0 for id. Since v31.1 there are no root prompts: grant root ahead of time under Superuser > Grant Superuser, where the ADB shell is listed as Shell, and only then run su. On v30.7 and older, the first time a shell or app asks for root the Magisk app shows a prompt, and your choice is saved in the Superuser tab.
What is MagiskSU? Magisk's root implementation. su is a link to the magisk binary, which hands the request to the Magisk daemon over a socket. There is no separate MagiskSU download. How the binary ends up in PATH is explained on how Magisk works.
How a root request is decided
What happens when you type su
- 1su clientParses options, connects to Magisk's socket
- 2magiskd checks the callerUID, multiuser mode, saved grant
- 3No saved grant?v30.7: the app asks you. v31.1: refused
- 4Root process forkedMount namespace, groups, SELinux context applied
- 5I/O relayedThrough a pseudo-terminal or your pipes; exit code returned
The daemon looks up the calling UID in its database (/data/adb/magisk.db). Root (uid 0) and the Magisk app itself are always allowed. Everything else depends on the saved policy for that UID: Allow, Deny, or Restrict, which grants root with all Linux capabilities dropped. With no saved policy, v30.7 asks the Magisk app to show the prompt and waits for your answer (or the timeout); v31.1 refuses immediately. The Multiuser mode setting decides whose grants apply to apps in secondary users or work profiles.
Superuser settings in the Magisk app
| Feature | v30.7 (previous) | v31.1 (current) |
|---|---|---|
| Prompt dialog when an app asks for root | Yes | No |
| Grant an app before it has asked | NoApps appear after their first request | YesSuperuser tab, Grant Superuser |
| Superuser access (Apps and ADB / Apps only / ADB only / Disabled) | Yes | No |
| Automatic response and Request timeout | Yes | No |
| Reauthenticate after upgrade, Tapjacking protection | Yes | No |
| User authentication | Yes | Yes |
| Multiuser mode, Mount namespace mode | Yes | Yes |
| Superuser notification | YesNone or Toast | YesNone, Toast or Notification |
| Restrict root capabilities | Yes | Yes |
All options
Usage: su [options] [-] [user [argument...]] in v30.7, su [options] [--] [user [argument...]] in v31.1. The table follows each version's option parser, not just its help text.
| Option | Effect | Version notes |
|---|---|---|
-c, --command CMD | Run a command instead of an interactive shell | v30.7: an su option that takes all remaining arguments. v31.1: no longer parsed by su; it is passed to the shell, which runs sh -c CMD. Quote the command in both. |
-i, --interactive | Force a pseudo-terminal even with -c (for commands like top) | Both |
-s, --shell SHELL | Use another shell instead of /system/bin/sh | Both |
-g, --group GID | Primary group (numeric) | Handling fixed in v31.1 |
-G, --supp-group GID | Add a supplementary group; repeatable. Without -g, the first one is also the primary group. | Handling fixed in v31.1 |
-Z, --context CONTEXT | Run with another SELinux context. -z and -cn are accepted as old aliases. | Both |
-t, --target PID | Use the mount namespace of process PID; 0 means Magisk's global namespace | Both |
-M, -mm, --mount-master | Run in the global mount namespace (same as -t 0). Can't be combined with -t. | Both; dropped from the v31.1 help text but still accepted |
-d, --drop-cap | Drop all Linux capabilities | Not the default since v30.7 |
-m, -p, --preserve-environment | Keep the caller's whole environment | Both |
-, -l, --login | Start a login shell | v30.7 only. In v31.1 they are no longer su options and go to the shell. |
-v, --version / -V | Print version / version code and exit | Both |
-h, --help | Show help | Both |
-- | Stop option parsing | v31.1: parsing also stops at the first unknown option, and everything from there goes to the shell |
user | User to switch to, by name or UID (default root) | Both |
Order matters in v31.1. Its parser stops at the first argument that is not an su option, so put su's own options first, then the user, then the shell arguments: su --drop-cap 2000 -c id works, while su 2000 --drop-cap -c id hands --drop-cap to the shell. v30.7 accepted options in any position.
Error messages come straight from the parser: Invalid GID, Invalid PID, Can't use -M and -t at the same time, and in v31.1 option '-s' requires an argument (with the option name). Each prints the help text after it.
Worked examples
Over adb shell with a command, the session has no terminal, so programs that need one (top, editors) need adb shell -t and su -i. For an app or script, check root with su -c id and look for uid=0; on v31.1 make sure users know to grant the app first. If an app only needs elevated access to Android APIs rather than full root, Shizuku may be enough.
Recent changes
- v30.1: added the Restrict root capabilities option, which can apply per app.
- v30.7: MagiskSU no longer drops Linux capabilities by default, even when switching to a non-root UID. Use
--drop-capif you need them dropped. - v31.1 (current stable): root prompts, the Superuser access mode and the re-authentication setting were removed; access is granted ahead of time.
-g/-Ghandling was fixed, unknown options are forwarded to the shell, and signal handling for commands run by the daemon was fixed.
How root access is contained
Root shells run in Magisk's own magisk SELinux domain, so SELinux stays enforcing for everything else. A fixed set of client domains (zygote, shell, and system, privileged and regular apps) may connect to Magisk's socket, which carries su requests, and share the root shell's pseudo-terminal. Whether a request is allowed is then decided by the daemon from your Superuser settings. Older documentation described a separate magisk_client domain; current releases no longer use it. See how Magisk works. To change properties from a root shell, use resetprop.
Errors and questions
su says Permission denied
The Magisk daemon refused the request. su prints Permission denied and exits with code 13.
v31.1: there is no prompt any more. Open the Magisk app, go to Superuser, tap Grant Superuser and switch on the app (the ADB shell is listed as Shell; you can search for "adb"). A refused request is not logged and shows no toast unless the app already has an entry.
v30.7: check the Superuser tab for a Deny entry, and in Settings check that Superuser access is not Disabled, Apps only (blocks adb shell) or ADB only (blocks apps), and that Automatic response is not Deny. If the prompt timed out, try again and answer it. Requests are also refused if the Magisk app is not installed.
su: not found or su: inaccessible or not found
Magisk is not running, or it did not get to mount its tools. Run magisk -c: if that is also not found, the patched image is not the one booting. Follow Magisk installed but root not working.
If magisk -c works but su does not, see where Magisk put it with command -v su. Magisk adds su to a directory in PATH at boot; a shell started with a changed PATH may not see it. Calling it by full path works around that: $(magisk --path)/su, since Magisk's tmpfs directory holds links to all its applets.
Cannot connect to daemon
The su client could not reach magiskd, usually because Magisk failed at boot or the phone booted in a state where Magisk was not loaded (for example the stock image after an OTA update). Reboot, then check with magisk -v, which asks the running daemon for its version. If that fails too, reinstall Magisk; after an OTA update see updating Magisk and keeping root.
An app asks for root but no prompt appears
On v31.1 that is expected: prompts were removed. Grant the app in Superuser > Grant Superuser, then restart it.
On v30.7, check that the Magisk app is installed and not disabled, that Automatic response is Prompt, and that the app is not already in the Superuser list as denied. A leftover hidden (repackaged) Magisk app can also block the prompt; see root not working.
I mounted something as root but apps don't see it
Root shells use the Inherit namespace mode by default, so a mount made in an adb shell root session lives in the shell's mount namespace only. Use su -M (or su -t 0) to run in Magisk's global namespace, or change Mount namespace mode to Global namespace in Settings.
Do I need quotes with su -c?
Yes, quote the whole command: su -c 'ls -l /data'. On v30.7, -c joins every remaining argument into one command, so the unquoted form also works. On v31.1, arguments are passed to the shell as is; the unquoted form su -c ls -l /data still runs for compatibility, but Magisk logs it as a syntax error and the toast adds "Warning: Unsupported command line detected".
I'm root (uid 0) but still get Operation not permitted
Three common reasons. The app may be set to Restrict root capabilities (v30.1 and later), which runs it as uid 0 without Linux capabilities. You may have passed --drop-cap. Or the operation is blocked by something root does not control, such as a read-only partition (Magisk never remounts /system read-write; use a module instead) or by AVB integrity checks.
How do I check which su is running?
su -v prints the version followed by :MAGISKSU, and su -V prints the version code. If the output has no MAGISKSU, another root solution's su is first in PATH; the Magisk app also warns about a "su" binary not from Magisk.
How do I run a command as another user, such as shell?
Name the user before the command: su 2000 -c id or su shell -c id. Put any su options before the user name, because v31.1 passes everything after it to the shell. Since v30.7, switching to a non-root user keeps the root capabilities unless you add --drop-cap, so scripts that rely on losing privileges must add it.
No match. Try another word from the error message.
Sources
This page is written from the sources below. If anything here disagrees with them, the upstream source is correct.
- Magisk tools reference: su (topjohnwu)
- Magisk changelog: MagiskSU changes in v30.1, v30.7 and v31.1 (topjohnwu)
- Magisk source: su client and usage text, native/src/core/su/su.cpp at v30.7 (topjohnwu)
- Magisk source: su client at v31.1 (topjohnwu)
- Magisk source: root request handling, native/src/core/su/daemon.rs at v31.1 (topjohnwu)
- Magisk internal details: SELinux (topjohnwu)
Found a mistake or something out of date? Tell us and we will check it against the source and fix the page. Confirmed corrections are listed in the corrections log.
Report a problem with this page