If you’re getting “sudo: command not found” or “sudo: effective uid is not 0” on your Linux system, you’re locked out of administrative tasks. This guide walks you through the most common causes and fixes, from simple PATH issues to recovering a broken sudoers file, so you can regain root privileges safely.
What You’ll Need
- Access to a root shell (or a live USB if you’re locked out entirely)
- Basic familiarity with the command line
- Patience – some fixes require a reboot
Step-by-Step
- Check if sudo is installed. Run
which sudoorcommand -v sudo. If nothing appears, sudo may not be installed. On Debian/Ubuntu, install it withapt install sudoas root. On RHEL/Fedora, usednf install sudo. - Verify your PATH includes /usr/bin or /usr/sbin. If
sudoexists but you get “command not found,” your PATH is missing the directory. Runecho $PATHand look for/usr/binand/usr/sbin. Temporarily set PATH withexport PATH=/usr/bin:/bin:/usr/sbin:/sbinand try sudo again. To make it permanent, edit~/.bashrcor/etc/profile. - Check if your user is in the sudo group. On Debian/Ubuntu, users must be in the
sudogroup. Rungroupsto see your groups. If missing, log in as root and add your user:usermod -aG sudo username. On RHEL/Fedora, the group iswheel. - Inspect the sudoers file for syntax errors. A broken sudoers file can cause sudo to fail. As root, run
visudoto open the file safely. Look for lines that are malformed or have incorrect permissions. If you see errors, fix them and save. - Repair the sudoers file if it’s corrupted. If you can’t run sudo at all, boot from a live USB, mount your root partition, and edit
/etc/sudoersdirectly. Remove any suspicious lines or restore from backup (/etc/sudoers.bakif it exists). - Check file permissions on sudo and sudoers. The sudo binary should be owned by root and have setuid bit set. Run
ls -l /usr/bin/sudo– you should see-rwsr-xr-x. If the setuid bit is missing, as root runchmod 4755 /usr/bin/sudo. The sudoers file should be owned by root:root with permissions 0440 – fix withchown root:root /etc/sudoers && chmod 0440 /etc/sudoers. - Verify sudo isn’t aliased or shadowed. Run
type sudoto see if it’s an alias or a function. If it’s aliased to something else, remove the alias from your shell config. - Test sudo with a simple command. After each fix, run
sudo -vto validate your credentials, thensudo whoami– it should printroot.
Common Mistakes
- Editing sudoers with a regular editor. Always use
visudo– it checks syntax before saving. A single typo can lock you out. - Forgetting to log out and back in. After adding a user to a group, the change only takes effect on the next login.
- Assuming sudo is installed. Minimal installs often omit sudo. Check first.
- Overwriting sudoers with wrong permissions. If you set permissions to 0644 or change ownership, sudo will refuse to run.
Tips
- Always keep a root shell open when editing sudoers – if you make a mistake, you can fix it without rebooting.
- Use
pkexecas a fallback if sudo is completely broken – it uses PolicyKit and may still work. - Back up your sudoers file regularly:
cp /etc/sudoers /etc/sudoers.bak. - If you’re on a system with SELinux, check the context:
ls -Z /usr/bin/sudo– it should besystem_u:object_r:sudo_exec_t:s0.
Troubleshooting
sudo: effective uid is not 0, is /usr/bin/sudo owned by root? This means the setuid bit is missing or ownership is wrong. Fix as root: chown root:root /usr/bin/sudo && chmod 4755 /usr/bin/sudo.
sudo: /etc/sudoers is world writable – Run chmod 0440 /etc/sudoers as root. This usually happens after manual editing.
sudo: no tty present and no askpass program specified – This occurs when running sudo in a script without a terminal. Use sudo -S to read the password from stdin, or configure NOPASSWD in sudoers for that command.
sudo: unable to resolve host – This is a DNS/hostname issue. Check /etc/hostname and /etc/hosts – the hostname should match an entry in hosts. Add 127.0.1.1 yourhostname if missing.
Still not working? Boot from a live USB, mount your root partition, and chroot into it. Then you can run apt reinstall sudo or yum reinstall sudo to restore the binary and config.
Frequently Asked Questions
Why do I get “sudo: command not found” even though I’m root?
Your PATH doesn’t include /usr/bin or /usr/sbin. Set PATH manually or use the full path /usr/bin/sudo.
What does “sudo: effective uid is not 0” mean?
The sudo binary isn’t setuid root. It must be owned by root and have the setuid bit set (permissions 4755).
Can I fix sudo without rebooting?
Yes, if you have root access via su or a live session. Most fixes are immediate; only group changes require re-login.
How do I recover from a broken sudoers file?
Boot from a live USB, mount your root partition, and edit /etc/sudoers directly. Remove the bad line or restore a backup.
Is it safe to use pkexec instead of sudo?
Yes, pkexec is a secure alternative, but it may require configuration. It uses PolicyKit rules, which can be more complex to manage.
Why does sudo work for one user but not another?
That user isn’t in the sudo group (or wheel). Add them with usermod -aG sudo username and have them log out and back in.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- How to Check Xiaomi Phone Specs & Software Before Buying
- How to Cash Out Stablecoins to a Bank Account Safely
- Mute Unmute Notification Popup AirPods Fix
- Windows 10 Installation Error: Unexpected Restart Fix
- iPhone Stuck on Apple Logo? Fixes That Work
- Memoji Stickers on iPhone: Create & Use Them