Debian

How to fix debian sudo command not found

Before discussing how to fix sudo commands not found in Debian we will first discuss what Sudo is. Sudo means the superuser; as a superuser you have all the privileges which a root user can enjoy. Different distributions of Linux are such as Ubuntu, Fedora, and Mageia. Similarly, Debian is also an example of Linux general distribution. Ubuntu distribution is used for beginners whereas Debian is an advanced distribution that is used on an expert level. While working on Debian sometimes we found an error using the “sudo” command. It may be something like “sudo command not found”, “[user name] is not in the sudoers list” or maybe some other error that means the same.

This write-up is associated with the solution with which we can resolve this error. We will discuss both errors separately which are related to the sudo package, when we face them and how we can resolve these issues.

How to FIX: Debian sudo command not found

By default in Debian, the sudo command is installed but sometimes it happens that we use the sudo command and it generates the following error.

We simply enter the root user mode as:

$ sudo -s

So it means that the sudo package is not installed by default so to resolve this issue we simply go to the user mode and install the package. First, we will go to the root user mode.

$ su -

Update the repository first.

# apt update

Install the sudo package.

# apt install sudo -y

Exit the root mode.

# exit

To verify the installation of the error we will again enter the root by using sudo command.

$ sudo -s

The issue which has been discussed at the start is now resolved.

How to add user to sudoers file to resolve the error

We simply run the command of the list of disks on Debian.

$ sudo fdisk -l

We have the output, “zhammad is not in the sudoers file . This incident will be reported.”, this is an error which means we cannot use the sudo command. Sudo command is an administrative command which is used with those commands which need administrative permissions. Now it means the user “zhammad” does not have the administrative rights so to access those permissions we have to install the “sudo command” manually and give the administrative privileges to this user.

We will switch the user to administrative user which is “hammad” in our case. So by using the “su command” we switch to hammad from zhammad.

$ su hammad

Now as we switch the user to hammad, we will go to the root mode.

$ sudo -s

Update the repository of Debian by using the update command.

# apt-get update

As we can see in the output, the repository is updated and all the packages are up to date so no need to upgrade the repository. Now we add the new user in the list of sudoers file by using the command.

# usermod -aG sudo zhammad

The user has been added to the list of sudoers and for the verification of this we used the command of “id”.

# id zhammad

In the above output, we see the zhammad user is also added to the list of sudo. After verifying this we will exit the root mode by typing “exit”.

# exit

For switching back to the zhammad from hammad.

$ su zhammad

Again run the command of fdisk and confirm that the issue has been solved.

$ sudo fdisk -l

The command runs successfully and displays the list of disks. So our issue has been resolved.

Conclusion

Sudo is used for the commands which are making the changes in the root folder and administrative things. For a secure purpose, these permissions are only given either to the root user or the user which are allowed by the root user. We have discussed the solution of the issue in this write-up which is to resolve it by installing the sudo manually (if it is not installed so can be installed by this command else it is installed in Debian by default) and adding the user to the list of sudoers by switching to the administrative user account. I tried to assist you with the solution of “sudo command not found” in this write-up and hope this will help you in resolving the issue.

About the author

Hammad Zahid

I'm an Engineering graduate and my passion for IT has brought me to Linux. Now here I'm learning and sharing my knowledge with the world.