If you see the error “username not in the sudoers” in Debian 13, it means that your user account doesn’t have the permissions to run the sudo command. This problem is most common in fresh Debian installations or VPS environments. It can also occur on systems that have sudo misconfigured or removed. You must first temporarily log in as root and assign sudo permissions correctly.
This guide provides solutions for fixing “username is not in the sudoers file” in Debian 13.
- Why “username is not in the sudoers file” Error Occurs
- How to Fix “username is not in the sudoers file” in Debian 13
- Conclusion
Why “username is not in the sudoers file” Error Appears
Debian 13 displays this error because:
- The sudo group is not added to your user account
- Sudo is not installed on the minimal installation
- The sudoers file is corrupted, or has been incorrectly edited
- The system was only installed for non-sudo Users
How to Fix “username is not in the sudoers file” in Debian 13
Once you know why this error occurs, it is simple to fix. The solutions listed above will restore sudo effectively and safely, whether sudo is not present, the sudoers file is corrupted, or the user does not have permissions. You can easily regain administrative control over your Debian system by switching to root or repairing configuration files.
Choose one of the following solutions based on the state of your system.
Solution 1: Add the User to the Sudo Group
This is the most common solution, and it works for 95% systems.
Step 1: Switch to the root user
You must manually switch to the root account since your user is unable to run sudo. You can access the full administrative rights needed to fix sudo’s configuration by using the su – command.
|
su – |
|---|

Step 2: Add the user to the sudo group
Users in the sudo group are able to execute administrative commands on Debian. Add your user to the sudo group and instantly restore sudo functionality without having to modify system files manually.
|
usermod -aG sudo username |
|---|

Step 3: Activate the new group membership
You will need to refresh your session before the system can apply any new group permissions. Newgrp instantly reloads the group environment, allowing sudo work without having to log out.
|
newgrp sudo |
|---|

Solution 2: Install Sudo (If It’s Missing)
Some Debian cloud or minimal images do not include sudo as a default. This causes the error, even though there is nothing wrong with groups.
Step 1: Install the sudo package
Debian will not be able to execute sudo commands without the sudo package installed. This command installs the default configuration files for sudo and downloads them:
|
apt update apt install sudo |
|---|

Step 2: Grant your user sudo access
Sudo requires proper permissions from your user after installation. Add your username to the sudo group, and you will get full administrative rights.
|
usermod -aG sudo username |
|---|

Solution 3: Repair a Broken sudoers File
If you edit /etc/sudoers in the wrong way, sudo will not work for any user, including root, via sudo. This method fixes sudo in a safe way.
Step 1: Open sudoers using visudo
Syntax errors can cause your system to crash if you edit /etc/sudoers. Visudo checks for errors before saving to ensure you don’t corrupt sudo permissions.
|
sudo nano /etc/sudoers |
|---|
Step 2: Add the correct sudo group rule
This line is necessary for the sudo group to work. This line defines permissions for users in the sudogroup and restores normal access to the file if it was corrupted.
|
%sudo ALL=(ALL:ALL) ALL |
|---|

Solution 4: Give Sudo Access to One User Directly
Use this if you only want one user to have sudo rights, not everyone in the group.
Step 1: Open sudoers safely using visudo
Visudo is the only way to add direct user-specific permissions, as this will ensure that your changes won’t break the system. This also helps to maintain a secure format in the sudoers files.
|
sudo nano /etc/sudoers |
|---|
Step 2: Add user-specific sudo rights
This allows the user to have full administrative rights without the need for the sudo group. This is ideal for VPS configurations, where only one administrator account should have privileged access.
|
username ALL=(ALL:ALL) ALL |
|---|

Solution 5: Fix the Issue When Locked Out of SSH (No Root Login)
You must use the emergency tools provided by your VPS provider if sudo fails and root login is not enabled in SSH.
Step 1: Access the VPS console or recovery mode
You must use the emergency tools provided by your VPS provider if sudo fails and root login is not enabled in SSH.
Step 2: Reassign your user to sudo
Add your user to the sudo group once you’re in the recovery environment. This will immediately fix the issue. It is the fastest method to restore normal access.
|
usermod -aG sudo username |
|---|

Verify That Sudo Works
Run:
|
sudo whoami |
|---|

This command will check whether sudo is working correctly. It will return root if everything has been fixed. This confirms that your user now enjoys full administrative rights.
Conclusion
To fix the “username is not in the sudoers file” error on Debian 13, log in as the root user using su -, then add your user to the sudo group with usermod -aG sudo username and refresh permissions using newgrp sudo; if sudo is missing, install it with apt install sudo -y, and if the sudoers file is broken, repair it by running visudo and ensuring the line %sudo ALL=(ALL:ALL) ALL is present, which restores proper sudo permissions and allows your user to execute administrative commands again.








Leave feedback about this