Debian

How to Fix “sudo command not found” in Debian 12

How to Fix sudo Command Not Found in Debian 12

sudo also known as Super User Do, is a command line utility that enables Debian users to execute the command with root privileges. It is a great way to give admin rights to users without sharing the root password. Depending on the configuration of the/etc/sudoers file, you can perform various tasks as an admin or regular user.

Sometimes when Debian users try to run the sudo command, the error occurs saying: sudo command not found. This error prevents users from performing activities on the system, such as updating the repository, installing the applications, and more.

Quick Outline

 

Why Does the “sudo command not found” error occurs in Debian 12

The sudo allows users to run commands that they do not run with normal users. While working on the Debian terminal, users sometimes face an error that says: “sudo command not found” or “[user_name] is not in the sudo group”.

There can be various reasons for the occurrence of the sudo command not found error on Debian:

  • The sudo utility is not installed on your Debian system.
  • The $PATH variable is not properly set or included in the directory that contains sudo executables.
  • The user is not in the sudo group.

 

How to Fix “sudo command not found” in Debian 12

If you are encountering the above-mentioned error on your system, you can fix it by:

 

1: Install sudo in Debian 12

If you are receiving an error “sudo command not found”, then it is possible that sudo is not installed on your system. To install sudo on Debian 12, properly follow the below-given steps:

Step 1: First, switch to the root user on Debian 12 using the following command:

su -

Step 2: Then run the update command to update the Debian repository before installing sudo:

apt update

Step 3: Once the process of updating the repository completes, execute the install command to install the sudo on your system:

apt install sudo -y

Step 4: Once sudo is installed on your system, exit the root user using the following command:

exit

Else, you can switch to another using the following command:

su username

 

2: Modify PATH Variable in Debian 12

When you execute the command, the shell finds the appropriate related program using the PATH variable which contains the list directories. Sometimes the directory containing sudo is not added to the PATH variable. You can view the directory of the sudo binary file using the following command:

which sudo

To check your current PATH on Debian, execute the below command:

echo $PATH

 

If the directory containing sudo is not added in the current PATH, then modify the PATH by adding the sudo directory. Here the path for the sudo directory is /usr/bin, execute the following command to add the PATH:

export PATH=$PATH:/usr/bin

Moreover, you can also open the bash configuration file by executing the following command:

nano ~/.bashrc

Add the following line at the end of this file and save the file:

export PATH="/usr/bin:$PATH"

To apply the changes either restart the terminal or execute the following command:

source ~/.bashrc

You should now be able to use sudo privileges to execute commands on your system.

 

3: Give sudo Privileges to a User in Debian 12

For running the sudo command for regular users, you should add that user to the sudo group. The reason is due to security reasons, the sudo privileges is disabled for normal users on the Debian system.

You can add a user to a sudo group in Debian 12 through the following two ways:

 

Add User to a sudo Group in Debian 12 Through the Terminal

You can follow one of these mentioned methods to add any user to a sudo group in Debian:

 

1: Add User to a sudo Group in Debian 12 with usermod Command

Adding a user to the sudo group will give all the sudo privileges and they can run any command using the sudo as a prefix. To add a user to a sudo group on Debian, you can use the usermod command given below:

sudo usermod -aG sudo username

Here:

-a: It appends the user to a specified group without removing the user from the existing group.

-G: It specifies the group to add the user to.

Here, I am giving sudo privileges to a user linuxways on Debian using the below command:

sudo usermod -aG sudo linuxways

Run the below-written command on the terminal to verify whether the user is added to sudo users or not:

groups linuxways

 

2: Add User to a sudo Group in Debian 12 by Editing a sudoers File

You can also edit the sudoers file to add any user to the sudo group and for that, you first need to switch to the root user from the following command:

su

Next, preview the visudo file using any editor on your system; as in the below example, I am using nano editor to open and edit the file:

visudo

OR

nano /etc/sudoers

Write the below-written line under the User privilege specification and replace the username with the specified name of the user you want to give the user sudo privileges:

username ALL=(ALL:ALL) ALL

Use Ctrl + X, add Y and press Enter to save the file.

Once done following the above-mentioned steps, you should be able to run the sudo command now:

How to Add a User to sudo Group in Debian 12 Through GUI

You can also add a user to a sudo group from system settings in Debian using the following steps:

Step 1: First, navigate to Activities and open the Settings of the system:

Step 2: Scroll down to find the Users:

Step 3: Click on Unlock and enter the administrative password to continue:

Step 4: Under Other Users, click on the name of the user you want to add to a sudo group:

Step 5: Turn the toggle on for Administrator:

This will add the users to a sudo group in Debian 12 from GUI.

 

Conclusion

In Debian 12, sudo provides users a convenient way to temporarily grant other users access to system resources, such as updating or installing packages. While using sudo sometimes, users may encounter the sudo command not found error on Debian. This error mostly occurs when sudo is not installed, variable PATH is not properly set or the user is not added to a sudo group. To resolve this error, install the sudo, add the user to a sudo group through the terminal or GUI, or add the directory that contains sudo executable files to the PATH variable so the system can execute it. The above-mentioned guide will help you fix these issues so that you will be able to run sudo commands and manage packages on your system.

Similar Posts