keepcalculator

06 Numbers and Powers

Sudo Replacements: Which One Makes It Useless?

Card No. 06·83652 · Updated · Standard formula, shown below

The short answer: the only “replacement” that makes sudo entirely useless is one that removes privilege separation itself—if a program or user can bypass the kernel’s permission checks, no sudo-like tool can protect the system. This article explains why sudo exists, what its realistic replacements are, and why none of them can substitute for the underlying security model.

Why sudo exists

Sudo (“superuser do”) is a Unix/Linux command that lets a permitted user run a command as another user, usually root. It was created in the late 1980s by Bob Coggeshall and Cliff Spencer at the University of California, Davis, as a more controlled alternative to logging in as root or using the su command. The core idea is least privilege: you don’t stay root all day; you elevate only for specific commands, and every elevation is logged.

Without sudo, you’d either share the root password (bad) or give everyone full admin rights (worse). Sudo adds an audit trail and allows fine-grained rules like “user alice can restart the web server but not read /etc/shadow.”

Realistic sudo replacements

Several tools aim to replace sudo, but they all work within the same privilege model. None of them remove the need for a trusted kernel and a root account.

  • doas – A minimal alternative from OpenBSD, now ported to Linux. It’s simpler than sudo: one config file, no timestamps by default, and a smaller attack surface. Many users switch to doas for its clarity.
  • run0 – A systemd-based tool (introduced in systemd 256) that runs commands via a transient systemd service, isolating the process and giving it a pseudo-TTY. It’s not a drop-in replacement but a different mechanism for privilege elevation.
  • su – The classic switch-user command. It requires the target user’s password (usually root) and doesn’t offer fine-grained rules. It’s not a true sudo replacement because it’s all-or-nothing.
  • PolicyKit (polkit) – Not a direct sudo replacement but a system-wide authorization framework. Graphical apps use it to prompt for admin rights. It’s more complex and often used alongside sudo.

What makes sudo entirely useless?

Here’s the key: sudo is useless if the attacker already has root or if the kernel’s permission model is broken. For example, if a vulnerability lets a normal user escalate to root directly (a kernel exploit), sudo’s rules are irrelevant—the attacker never goes through sudo. Similarly, if a user can modify sudo’s own configuration or binary (because of weak file permissions), they can grant themselves any privilege.

Another scenario: if you run a container with --privileged or mount the host’s /proc in a way that allows kernel exploits, sudo’s protections are moot. In short, sudo is a gatekeeper, not a wall. The wall is the kernel’s user/group permission system. If that wall crumbles, sudo is just a formality.

How to choose between sudo, doas, and run0

Your choice depends on your priorities:

  • Simplicity and security: doas. Its config is one line like permit alice as root. Fewer features mean fewer bugs. OpenBSD’s doas was designed to be auditable.
  • Integration with systemd: run0. It uses the same systemd infrastructure, so it can integrate with journald and resource control. It also avoids the SUID-bit (setuid) mechanism, which is a common attack vector.
  • Compatibility and features: sudo. It’s installed by default on most distros, supports LDAP, and has extensive logging. If you need complex rules, sudo is still the most mature.

Common problems and misconceptions

One misconception is that sudo is “unsafe” because of its SUID bit. SUID binaries run with the owner’s privileges (root), so if an attacker finds a bug in sudo, they could gain root. That’s why doas and run0 avoid SUID (run0 uses systemd’s D-Bus). But this doesn’t make sudo useless—it just means you should keep it updated.

Another common mistake: people disable sudo’s password prompt with NOPASSWD for convenience. That means any user who can access your session (even via a locked screen) can run root commands. It’s a trade-off between convenience and security.

Security best practices for any sudo-like tool

  • Always use a strong password for your user account, not just root.
  • Limit sudo rules to the minimum necessary commands.
  • Enable logging and review logs regularly.
  • Keep the tool and the kernel updated to patch known vulnerabilities.
  • Never give sudo rights to a service account that runs web-facing processes.

Alternatives to privilege elevation

Sometimes you don’t need sudo at all. For example, you can use file capabilities (like cap_net_bind_service) to let a non-root process bind to port 80, or use user namespaces in containers to give a process root-like powers inside a sandbox. These approaches reduce the need for a global root account. However, they require careful configuration and don’t replace the need for a root user entirely.

Frequently Asked Questions

Is doas a drop-in replacement for sudo?

Not exactly. The command syntax is similar (doas command), but the config file is different. You’ll need to rewrite your sudoers rules into doas.conf. Some scripts that use sudo-specific flags (like -u) may need adjustments. For most daily use, doas works fine.

Does run0 work on all Linux systems?

No. run0 requires systemd version 256 or later, which is present on many modern distros (like Fedora 40+ and Arch) but not on older ones or on systems that use other init systems (like Alpine or Gentoo with OpenRC).

Can I use sudo without a password?

Yes, by adding NOPASSWD to the rule, but it’s a security risk. If someone gains access to your session, they can run any allowed command without authentication. Only use this for specific, low-risk commands.

What is the difference between sudo and su?

sudo runs a single command as root (or another user) after authenticating with your own password, and it logs the action. su switches you to another user entirely, requiring that user’s password, and gives you a full shell. sudo is more granular and auditable.

Is sudo vulnerable to the “sudo bash” trick?

If you have sudo rights to run bash (or any shell), you can effectively get a root shell. That’s not a vulnerability—it’s by design. If you want to prevent that, don’t grant sudo to shells or to commands that can spawn shells (like vim or less).

What should I do if sudo is broken?

If sudo is misconfigured and you can’t run any commands, boot into recovery mode or use a live USB to fix the sudoers file. Always keep a root shell open when editing sudoers to avoid locking yourself out.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →