What "Is Not In The Sudoers File" means and why it appears

When you see the message "user is not in the sudoers file," Linux is telling you that your account does not have permission to run a command with sudo — the tool that lets you perform administrative tasks. Sudo stands for "superuser do," and it acts as a gatekeeper: only accounts listed in the sudoers file can use it. Without that permission, you cannot install software, change system settings, or perform other tasks that require root-level access.

This error appears most often when you are trying to install a program, update your system, or change a file that belongs to the root user. The message itself is straightforward — your account simply is not authorized — but the fix depends on whether you have physical access to the machine and whether another account with sudo permission already exists.

The sudoers file is a special configuration file that lives at /etc/sudoers. It is protected by the system, which means you cannot edit it with a regular text editor. You must use a tool called visudo, which checks your changes for errors before saving them. This protection exists because a mistake in the sudoers file can lock you out of your own system.

Key Takeaways

  • The sudoers file controls who can run commands with sudo, and your account must be listed there to use administrative tools.
  • If another user account on the same machine already has sudo permission, ask that person to add you to the sudoers file using the visudo command.
  • If you are the only user or have physical access to the machine, you can boot into single-user mode or use a live USB to edit the sudoers file directly.
  • Never edit /etc/sudoers with a regular text editor — always use visudo, which prevents syntax errors that could lock you out.
  • The most common fix is a single line added to the sudoers file: your username, followed by ALL=(ALL:ALL) ALL.

Ask another user with sudo permission to add you

If you share the machine with someone else who already has sudo access, this is the fastest solution. That person can add your account to the sudoers file in about one minute. They will open a terminal and type sudo visudo, which opens the sudoers file in a text editor.

Inside the file, they will find a section that looks like this:

root ALL=(ALL:ALL) ALL %sudo ALL=(ALL:ALL) ALL

They will add a new line with your username. If your username is "alex," the line will be:

alex ALL=(ALL:ALL) ALL

After saving and exiting (in most editors, Ctrl+X, then Y, then Enter), you will be able to use sudo immediately. The next time you open a terminal, you can run commands with sudo and will be prompted for your password instead of seeing the "not in the sudoers file" error.

Use single-user mode if you are the only user

If you are the only person with access to the machine and no other account has sudo permission, you can boot into single-user mode. This is a special startup state where the system runs with minimal services and grants you root access without requiring a password. From there, you can edit the sudoers file directly.

The steps vary by Linux distribution. On Ubuntu or Debian, restart your computer and hold Shift while it boots. You will see a menu; select "Advanced options for Ubuntu" (or Debian), then choose the option that says "recovery mode." The system will boot into a root shell.

Once you are in the root shell, type mount -o remount,rw / to make the file system writable. Then type visudo to open the sudoers file. Add your username with the line your_username ALL=(ALL:ALL) ALL, save, and exit. Restart the computer normally, and you will have sudo permission.

On Fedora or Red Hat systems, the process is similar but the boot menu looks different. Restart, press E at the boot menu, find the line that starts with "linux," go to the end of that line, and add rd.break. Press Ctrl+X to boot. Then type mount -o remount,rw /sysroot, followed by chroot /sysroot, then visudo to edit the file.

Boot from a live USB if you cannot access single-user mode

Some systems are configured to prevent single-user mode access, or you may not remember the root password. In that case, a live USB — a bootable drive with a complete Linux system on it — lets you access the file system from outside the installed operating system.

Create a live USB using a tool like Balena Etcher or Rufus on another computer. Download an ISO file for your Linux distribution (Ubuntu, Fedora, or whichever you use), insert the USB into the locked machine, and boot from it. When the live system starts, open a terminal and mount your hard drive. You can then navigate to the sudoers file and edit it with visudo.

The exact commands depend on your setup, but the general process is: identify your hard drive partition with lsblk, create a mount point with mkdir /mnt/target, mount the partition with mount /dev/sdX1 /mnt/target (replacing sdX1 with your actual partition), then edit the file with sudo visudo -f /mnt/target/etc/sudoers.

Understand what each part of the sudoers line does

When you add a line to the sudoers file, you are writing a rule that tells the system what that user is allowed to do. The line alex ALL=(ALL:ALL) ALL breaks down like this:

alex is the username. ALL (the first one) means this rule applies on all machines — important if you manage multiple computers from one sudoers file. (ALL:ALL) means the user can run commands as any user and any group. The final ALL means the user can run any command. Together, this line gives alex full administrative access.

You can also create more restrictive rules. For example, alex ALL=(ALL) /usr/bin/apt would let alex run only the apt package manager with sudo, not any other command. Or alex ALL=(ALL) NOPASSWD: /usr/bin/reboot would let alex reboot the machine without typing a password. These restrictions are useful on shared systems, but for a personal machine, the full access line is standard.

Verify the change worked

After you have edited the sudoers file and saved it, open a new terminal window and type sudo whoami. The system will ask for your password. Type it in, and if the command returns "root," the change worked. You now have sudo permission.

If you see the "not in the sudoers file" error again, the edit did not save properly or visudo rejected it due to a syntax error. Go back and check that your username is spelled correctly and that the spacing matches the example. Visudo should have warned you about errors before saving, but if something went wrong, repeat the editing steps.

You can also check your permission by typing sudo -l, which lists all the commands you are allowed to run with sudo. If the sudoers file was edited correctly, this command will show your rules instead of an error.

Prevent this error on new accounts

If you manage a Linux machine and create new user accounts, add them to the sudoers file right away. The easiest way is to add them to the sudo group (on Ubuntu and Debian) or the wheel group (on Fedora and Red Hat). Users in these groups automatically have sudo permission without needing individual lines in the sudoers file.

To add a new user to the sudo group, type sudo usermod -aG sudo newusername. The user will have sudo access the next time they log in. This approach is cleaner than editing the sudoers file for each person, especially on systems with many users.

Frequently Asked Questions

Can I edit /etc/sudoers with nano or vi instead of visudo?

You can open the file with those editors, but you should not. Visudo checks your changes for syntax errors before saving. If you make a mistake in the sudoers file using a regular editor, you could lock yourself out of sudo access entirely. Visudo prevents that by validating the file first.

What if I made a mistake and now I cannot use sudo at all?

Boot into single-user mode or use a live USB to access the sudoers file again. Remove the line you added or fix the syntax error. Visudo will tell you what is wrong if you try to save an invalid file, so use it to correct the problem.

Do I need to restart the computer after editing the sudoers file?

No. The changes take effect immediately. Open a new terminal window and test with sudo whoami. You do not need to log out or restart.

Why does the system use a special file and a special editor for sudo permissions?

The sudoers file controls access to root-level commands, which can change or delete anything on the system. Visudo prevents typos and syntax errors that could accidentally lock you out or create security holes. The protection is there to keep you from breaking your own system.

Can I add a group to the sudoers file instead of individual users?

Yes. A line like %developers ALL=(ALL:ALL) ALL gives sudo access to everyone in the "developers" group. The percent sign tells the system it is a group name, not a username. This is useful on systems where many people need the same permissions.