Bash sudo command not found как исправить

There are many scenarios when you get "sudo command not found error" and you keep looking for solutions on the internet to fix it. One of the common examples,

There are many scenarios when you get «sudo command not found error» and you keep looking for solutions on the internet to fix it. One of the common examples, when you have installed Debian with a minimal package and trying to run sudo. For me whenever I try to ssh into any of the remote servers and run sudo, I get this «bash: sudo commands not found error». So I decided to write a post, which covers all the scenarios of this famous error.

Below mentioned errors will be covered in this post. so if you are getting any of the following errors, this post will definitely solve your error —

  • sudo command not found mac
  • sudo command not found ubuntu
  • sudo command not found debian
  • zsh sudo command not found
  • sudo command not found windows
  • sudo command not found centos
  • bash: /usr/bin/sudo: No such file or directory

These are the common scenarios that result in this error —

  • You have installed a linux distribution with minimal package like Debian
  • Sudo is not installed
  • Path is not setup for sudo command
  • You are trying to ssh a remote server first time and sudo is not working

Before getting into the solutions, if you are a newbie let’s understand why sudo is used?

Table of Contents

  • 1 Why sudo is used in Linux before every command?
  • 2 How to fix sudo command not found error in Debian/Ubuntu like Distros
  • 3 Solution-1 Check and install sudo package
  • 4 Solution2 — Setup path variable to fix sudo command not found errors
  • 5 Fix «sudo command not found error» in Fedora/AlmaLinux/Rocky Linux Distros
  • 6 Solution3- Install sudo and add user to «Wheel» group to fix sudo errors
  • 7 Frequently asked questions on sudo
  • 8 Ending Note

Why sudo is used in Linux before every command?

Sudo is one of the famous prefixes to any command you run in the Linux world. It allows running any Linux command with elevated privileges to run administrative tasks. Also, the operations which are only permitted by a root user can be done using a normal user with sudo rights. The «sudoers» file controls, who can use the sudo command to gain elevated access and location is /etc/sudoers in all Linux distributions.

How to fix sudo command not found error in Debian/Ubuntu like Distros

As we discussed already, there may be many reasons to encounter this error. As you will see in the image, running the «sudo ifconfig -a» command results in «bash: /usr/bin/sudo: No such file or directory error«. I am running this command in Ubuntu 21.04 installed as VM.

bash sudo command not found error in Ubuntu

Let’s deep dive and find the fixes for different scenarios —

Solution-1 Check and install sudo package

This is very uncommon when sudo is not installed by default with Linux installation. Still, you may get this situation when you have installed the Debian Linux with the minimal package. Follow these steps to fix it —

Step1.1 List installed packages in Ubuntu and look for the «sudo» package

$ apt list --installed | grep -i sudo

check installed packaged list for sudo

If you can find package name sudo with «installed» status as shown in the image. Then you can directly move to solution-2 to fix the «sudo: command not found error«.

If you don’t have the sudo package installed, run the following command to install it in Ubuntu or Debian based distros. You would need root access to achieve this.

Step1.2 Switch to root user

$ su root

Enter «root» password, when prompted.

If you don’t have a root password, then follow this link to reset your root password.

Step1.3 Run apt command to install sudo package in Ubuntu/Debian

# apt install sudo

Refer to the following image for reference.

install sudo to fix sudo command not found in ubuntu

Step1.4 Give sudo rights to your own user by adding it to the sudo group

# usermod -aG sudo yourusername

For example, I will add my user «dev» to sudo group —

# usermode -aG sudo dev

add user to sudo group

Step1.5 Verify your user is added to the sudo group

Open /etc/passwd file and check whether your user is added to the sudo group or not.

# cat /etc/group | grep -i username

I will check for my user «dev» in this example.

 # more /etc/group | grep -i username 

check user has been added to sudo group

Step1.6 Make sure your sudoers file have sudo group added

  • Run visudo command to modify sudoers file and add the following line into it (if it is missing):
# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

Enable sudo group to execute any command in sudoers file

Press Ctrl + X and press «Y» to save the file and exit from the nano editor.

Exit from the root shell and check the sudo command functionality.

  • Run sudo -h command. Now you will not get any «sudo command not found error» as it’s fixed now.

sudo commands help

Solution2 — Setup path variable to fix sudo command not found errors

If you have a sudo package installed as explained in Step 1.1 and still you are getting sudo command not found error. It means you don’t have «/usr/bin/» setup in the PATH variable or your /etc/environment file got messed up.

To add sudo in your Path variable, add /usr/bin/ directory by following the method.

Step2.1 Switch to root user

$ su root

Enter root user password, when asked.

Step2.2 Run /usr/bin/sudo command to check whether it’s working or not

# /usr/bin/sudo -h

Step2.3 Edit /etc/environment file and add «/usr/bin" directory in PATH

# vi /etc/environment

Add path variable to fix sudo command not found Debian

Alternatively, you can also run export command to set up the path variable

export PATH=$PATH:/usr/bin

In case you are getting visudo and usermod command not found errors also. Make sure you add /usr/sbin in the PATH variable as shown in the last step.

Fix «sudo command not found error» in Fedora/AlmaLinux/Rocky Linux Distros

This section covers sudo error for all the Linux distros based on RedHat like Fedora, AlmaLinux, CentOS and Rocky Linux. I have Rocky Linux Installed as a virtual machine. The procedure is the same as explained earlier, Look for the package, install it and set the path variable, if required. But the commands will differ now.

Solution3- Install sudo and add user to «Wheel» group to fix sudo errors

You have the option to set up sudo during installation in RedHat based Linux distros. But if you forgot to do that, You must have access to the root user to set up sudo for your user.

Step3.1 — Login with root user and check for sudo package installation

Follow this link to reset your root password, in case you forgot or don’t have it.

Once you are done with login as root, open Terminal and type

# yum list installed | grep -i sudo

If you get the sudo package installed already skip to the next step3.3.

Step3.2 Install sudo package

You can use the «yum» or «dnf» command to install any package from the repository.

Update all old packages and refresh the repository.

# dnf update 

Then install the sudo package using the dnf or yum command.

# yum install sudo

or
 
# dnf install sudo

Install sudo to fix sudo command not found in Centos or Rocky Linux

Step3.3 Add user to the wheel group

The wheel group is already set to provide sudo access to run all commands. So is the quickest way is to add your user to this group. Switch to the root user first using su command

su -

Now run usermod command to add your user in the wheel group.

# usermod -a -G wheel "username"

For example, I will add my user «dev» as an example

 # usermod -a -G wheel "dev" 

Add user to wheel group to fix zsh sudo command not found error in Fedora

Step4.4 Check with the id command

Next, run the id command to see whether your user is part of the wheel group or not.

# id "username" 

Example: My user dev is part of 10(wheel) the group.

# id dev

check Id has been added to wheel group

Congrats! you must have fixed your «sudo command not found error » now and you can run all your privileged commands using sudo.

Frequently asked questions on sudo

Q1: Why is sudo not working?

These are many reasons when sudo may not work —

1. You don’t have a sudo package installed
2. If the sudo package is installed then the path variable is not set up correctly
3. Your system got broken and all your packages and permissions got messed up
4. Your user is not added to the sudo or wheel group based on your Linux distro.

Q2: How do I enable sudo?

If the sudo package is already installed based on your Linux distro run the following command. Replace «dev» with your username.

for Ubuntu and Debian based distros —

$ su root

Then run the usermod command to add your user to the sudo group

# usermode -aG sudo dev

For RedHat based distros —

Switch to root (superuser)

$ su -

Add to the wheel group.

# usermod -a -G wheel dev

Q3: How do I find sudo commands?

Open terminal and type sudo -h. It will show you all the sudo command options and arguments. You can also type man sudo to get the manual of the sudo command.

Q4: How do I fix sudo command not found Mac?

Run the following sequence of commands to fix the sudo command not found error in macOS.

1. Check the syntax of command and spelling of sudo, so that you are sure, you are not running the misspelt command

2. switch to root user
$ su -

3. Run the following command

In the case of OS prior to Catalina

# visudo /etc/sudoers

in the case of Catalina

# visudo /private/etc/sudoers

4. Add your user as follows in sudoers file —

username ALL=(ALL) ALL

replace username with your user. e.g John

Save and exit sudoers file

5. reopen the terminal and it will fix all your zsh: sudo command not found error in macOS.

Q5: Do I need to install sudo?

By default all the Linux or Unix distros have sudo installed. But in case you don’t, then you must install sudo. it is the recommended way to use root privileged commands (only when required) and helps to avoid mistakes that can break your system.

Ending Note

I have covered all the possible solutions to fix the sudo command not found error and I hope this tutorial is helpful to you. In case, none of the solutions works for you and your system has broken severly, Either re-install your system or let me know the issue via your comments.

I will try to help you to the best of my knowledge.

Keep Learning!!

I am trying to deploy django app.
When I print
apt-get update
I see

W: Unable to read /etc/apt/apt.conf.d/ - DirectoryExists (13: Permission denied)
W: Unable to read /etc/apt/sources.list.d/ - DirectoryExists (13: Permission denied)
W: Unable to read /etc/apt/sources.list - RealFileExists (13: Permission denied)
E: List directory /var/lib/apt/lists/partial is missing. - Acquire (13: Permission denied)
E: Unable to read /var/cache/apt/ - opendir (13: Permission denied)
E: Unable to read /var/cache/apt/ - opendir (13: Permission denied)
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?

When I print sudo apt-get update
I see

-bash: sudo: command not found

I tried to use su instead of sudo.
But it is strange.
For example I print su apt-get update
And nothing happens
I just see a new line,

(uiserver):u78600811:~$ su apt-get update
(uiserver):u78600811:~$

The same if I try to install some packages.
What do I do?

If it is useful info — I am using Debian

(uiserver):u87600811:~$ uname -a
Linux infong1559 3.14.0-ui16294-uiabi1-infong-amd64 #1 SMP Debian 3.14.79-2~ui80+4 (2016-10-20) x86_64 GNU/Linux

asked Mar 30, 2017 at 20:18

user2950593's user avatar

4

By default sudo is not installed on Debian, but you can install it. First enable su-mode:
su -

Install sudo by running:
apt-get install sudo -y

After that you would need to play around with users and permissions. Give sudo right to your own user.

usermod -aG sudo yourusername

Make sure your sudoers file have sudo group added. Run:
visudo to modify sudoers file
and add following line into it (if it is missing):

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

You need to relogin or reboot device completely for changes to take effect.

answered Feb 21, 2018 at 12:27

Maksim Luzik's user avatar

Maksim LuzikMaksim Luzik

2,2931 gold badge8 silver badges14 bronze badges

12

su and sudo are two different, but related commands. It is unusual for sudo not to be installed, but it may simply not be in your Path. Try /usr/bin/sudo command.

If indeed sudo is not available, you need as you surmised to use su, but it does not work in the same way as sudo. The simplest way to use it is to simply run:

su -

This will ask you for the root user’s password, at which point you should probably apt install sudo, log out of the root shell, and then proceed as normal.

Mind that unlike sudo, which asks you for your password, su will ask you for root‘s password.

answered Mar 30, 2017 at 20:28

DopeGhoti's user avatar

DopeGhotiDopeGhoti

71.4k8 gold badges94 silver badges132 bronze badges

6

Since it’s a commercial server you won’t have access to root account nor be able to operate with root privileges. This means you won’t be able to run sudo nor install packages. What you can try to do is:

  • Check if you have access to a compiler and compile what you want for yourself and in your home space.

  • Check if you can run a virtual machine. This might let you run your private instance of an OS, on which you would install packages.

answered Mar 30, 2017 at 21:04

0

In a new Debian server install I too found out that sudo is not installed by default, but it can be done as root:

$ su root
# apt install sudo

What puzzled me is that I still got errors with visudo and usermod:

# visudo
bash: visudo: command not found

# apt install visudo
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package visudo

Actually, visudo is included with the sudo package, it was just not in the PATH for root:

# dpkg -S visudo
sudo: /usr/sbin/visudo
sudo: /usr/share/man/man8/visudo.8.gz

So I added it to the root’s ~/.bashrc.

PATH=$PATH:/usr/sbin

Now it can find visudo and usermod which can be used to setup sudo access.

answered Oct 8, 2021 at 16:16

Nagev's user avatar

NagevNagev

4095 silver badges9 bronze badges

I am trying to deploy django app.
When I print
apt-get update
I see

W: Unable to read /etc/apt/apt.conf.d/ - DirectoryExists (13: Permission denied)
W: Unable to read /etc/apt/sources.list.d/ - DirectoryExists (13: Permission denied)
W: Unable to read /etc/apt/sources.list - RealFileExists (13: Permission denied)
E: List directory /var/lib/apt/lists/partial is missing. - Acquire (13: Permission denied)
E: Unable to read /var/cache/apt/ - opendir (13: Permission denied)
E: Unable to read /var/cache/apt/ - opendir (13: Permission denied)
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?

When I print sudo apt-get update
I see

-bash: sudo: command not found

I tried to use su instead of sudo.
But it is strange.
For example I print su apt-get update
And nothing happens
I just see a new line,

(uiserver):u78600811:~$ su apt-get update
(uiserver):u78600811:~$

The same if I try to install some packages.
What do I do?

If it is useful info — I am using Debian

(uiserver):u87600811:~$ uname -a
Linux infong1559 3.14.0-ui16294-uiabi1-infong-amd64 #1 SMP Debian 3.14.79-2~ui80+4 (2016-10-20) x86_64 GNU/Linux

asked Mar 30, 2017 at 20:18

user2950593's user avatar

4

By default sudo is not installed on Debian, but you can install it. First enable su-mode:
su -

Install sudo by running:
apt-get install sudo -y

After that you would need to play around with users and permissions. Give sudo right to your own user.

usermod -aG sudo yourusername

Make sure your sudoers file have sudo group added. Run:
visudo to modify sudoers file
and add following line into it (if it is missing):

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

You need to relogin or reboot device completely for changes to take effect.

answered Feb 21, 2018 at 12:27

Maksim Luzik's user avatar

Maksim LuzikMaksim Luzik

2,2931 gold badge8 silver badges14 bronze badges

12

su and sudo are two different, but related commands. It is unusual for sudo not to be installed, but it may simply not be in your Path. Try /usr/bin/sudo command.

If indeed sudo is not available, you need as you surmised to use su, but it does not work in the same way as sudo. The simplest way to use it is to simply run:

su -

This will ask you for the root user’s password, at which point you should probably apt install sudo, log out of the root shell, and then proceed as normal.

Mind that unlike sudo, which asks you for your password, su will ask you for root‘s password.

answered Mar 30, 2017 at 20:28

DopeGhoti's user avatar

DopeGhotiDopeGhoti

71.4k8 gold badges94 silver badges132 bronze badges

6

Since it’s a commercial server you won’t have access to root account nor be able to operate with root privileges. This means you won’t be able to run sudo nor install packages. What you can try to do is:

  • Check if you have access to a compiler and compile what you want for yourself and in your home space.

  • Check if you can run a virtual machine. This might let you run your private instance of an OS, on which you would install packages.

answered Mar 30, 2017 at 21:04

0

In a new Debian server install I too found out that sudo is not installed by default, but it can be done as root:

$ su root
# apt install sudo

What puzzled me is that I still got errors with visudo and usermod:

# visudo
bash: visudo: command not found

# apt install visudo
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package visudo

Actually, visudo is included with the sudo package, it was just not in the PATH for root:

# dpkg -S visudo
sudo: /usr/sbin/visudo
sudo: /usr/share/man/man8/visudo.8.gz

So I added it to the root’s ~/.bashrc.

PATH=$PATH:/usr/sbin

Now it can find visudo and usermod which can be used to setup sudo access.

answered Oct 8, 2021 at 16:16

Nagev's user avatar

NagevNagev

4095 silver badges9 bronze badges

The error happens because the binary you are trying to call from command line is only part of the current user’s PATH variable, but not a part of root user’s PATH.

You can verify this by locating the path of the binary you are trying to access. In my case I was trying to call «bettercap-ng». So I ran,

$ which bettercap-ng

output: /home/user/work/bin/bettercap

I checked whether this location is part of my root user’s PATH.

$ sudo env | grep ^PATH

output: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin

So sudo cannot find the binary that I am trying to call from commandline. Hence returns the error command not found.

You can direct sudo to use the current user’s PATH when calling a binary like below.

$ sudo -E env "PATH=$PATH" [command] [arguments]

In fact, one can make an alias out of it:

$ alias mysudo='sudo -E env "PATH=$PATH"'

It’s also possible to name the alias itself sudo, replacing the original sudo.

Please refer to this video for step by step solution

Permission denied

In order to run a script the file must have an executable permission bit set.

In order to fully understand Linux file permissions you can study the documentation for the chmod command. chmod, an abbreviation of change mode, is the command that is used to change the permission settings of a file.

To read the chmod documentation for your local system , run man chmod or info chmod from the command line. Once read and understood you should be able to understand the output of running …

ls -l foo.sh

… which will list the READ, WRITE and EXECUTE permissions for the file owner, the group owner and everyone else who is not the file owner or a member of the group to which the file belongs (that last permission group is sometimes referred to as «world» or «other»)

Here’s a summary of how to troubleshoot the Permission Denied error in your case.

$ ls -l foo.sh                    # Check file permissions of foo
-rw-r--r-- 1 rkielty users 0 2012-10-21 14:47 foo.sh 
    ^^^ 
 ^^^ | ^^^   ^^^^^^^ ^^^^^
  |  |  |       |       | 
Owner| World    |       |
     |          |    Name of
   Group        |     Group
             Name of 
              Owner 

Owner has read and write access rw but the — indicates that the executable permission is missing

The chmod command fixes that. (Group and other only have read permission set on the file, they cannot write to it or execute it)

$ chmod +x foo.sh               # The owner can set the executable permission on foo.sh
$ ls -l foo.sh                  # Now we see an x after the rw 
-rwxr-xr-x 1 rkielty users 0 2012-10-21 14:47 foo.sh
   ^  ^  ^

foo.sh is now executable as far as Linux is concerned.

Using sudo results in Command not found

When you run a command using sudo you are effectively running it as the superuser or root.

The reason that the root user is not finding your command is likely that the PATH environment variable for root does not include the directory where foo.sh is located. Hence the command is not found.

The PATH environment variable contains a list of directories which are searched for commands. Each user sets their own PATH variable according to their needs.
To see what it is set to run

env | grep ^PATH

Here’s some sample output of running the above env command first as an ordinary user and then as the root user using sudo

rkielty@rkielty-laptop:~$ env | grep ^PATH
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

rkielty@rkielty-laptop:~$ sudo env | grep ^PATH
[sudo] password for rkielty: 
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin

Note that, although similar, in this case the directories contained in the PATH the non-privileged user (rkielty) and the super user are not the same.

The directory where foo.sh resides is not present in the PATH variable of the root user, hence the command not found error.

Sometimes, when you try to run a command as the root user using sudo, you receive a «command not found» error. Here’s how to fix it.

When setting up a new Linux desktop or virtual machine, you may encounter the error: «sudo: command not found». This Linux error message can be infuriating, and prevent you from progressing further with your setup. Here’s what it means and how to fix it.

What Is «sudo» in Linux?

User accounts on Linux come with a limited set of privileges that prevent them from performing administrative tasks which may damage the system. These limited privileges may keep users from accessing certain areas of the filesystem or from executing certain files.

The one user who has no such restrictions on their actions is the root user. The root user can access any area of a Linux system, and execute any command on any file.

Because of this immense power, you should disable the root account and use sudo instead.

apt update without sudo fails

The sudo command is short for «superuser do» and allows a user who is part of the sudo group to execute a command as if they were the root user. It effectively gives them root powers and permissions—as long as they use sudo and authenticate with a password.

Why Is the sudo Command Not Found?

As well as being a useful command, sudo is a package. On most systems, sudo is installed by default. But this is not the case on all distros, and when you attempt to run a command using sudo you may receive the error, «sudo: command not found». This is especially common on newly installed Linux systems.

You may then try to install the sudo package with:

 sudo apt install sudo 
terminal output: sudo not found while trying to install sudo

This will fail because you are unable to use sudo to install packages as the root user.

How to Fix «sudo: command not found» on Linux

As your user cannot assume the privileges of the root user without already having sudo installed, you need to log out of your user account and log in as root.

As root, you can install the sudo package with the privileges this account possesses.

On Debian-based systems, enter:

 apt install sudo 

Then, add your user to the sudo group using:

 usermod -aG sudo your_username 

On Arch-based systems, enter:

 pacman -S sudo 

Then:

 usermod -aG wheel your_username 

You Can Now Run Commands With sudo on Linux!

You have successfully installed sudo and added your user to the sudo group, meaning that you can run any command and access any area without needing to log in as root. Use this power carefully, as elevated privileges can be dangerous.

Главная » Linux » Debian » Как исправить ошибку Sudo Command Not Found в Debian VPS

Опубликовано 06.07.2022

В этой статье мы покажем вам, как исправить ошибку sudo command not found в Debian 10 VPS.

Sudo — это программа для Unix-подобных компьютерных операционных систем. Команда sudo позволяет пользователям запускать программы с привилегиями суперпользователя. Она может означать «superuser do«, так как изначально это все, что она делала, однако сейчас она может означать «substitute user, do«, потому что sudo может выполнять команды и от имени других пользователей.

После установки Debian 10 вы не можете выполнить задачи с привилегиями, запустив команду sudo. И вы получите ошибку «sudo command not found in Debian 10«.

Исправление ошибки Sudo Command Not Found в Debian

Войдите на сервер Debian 10 под пользователем root.

Вход на сервер Debian

Вход на сервер Debian

После входа в систему выполните следующую команду, чтобы проверить ошибку sudo:

sudo apt update

Вы получите следующую ошибку:

-bash: sudo: command not found

Ошибка -bash: sudo: command not found

Ошибка -bash: sudo: command not found

По умолчанию пакет sudo находится в репозитории Debian 10 по умолчанию. Вы можете установить его с помощью команды apt, как показано ниже:

apt install sudo -y

Установка пакета sudo

Установка пакета sudo

После установки пакета Sudo вам нужно будет создать нового обычного пользователя и добавить его в группу sudo.

Сначала создайте нового пользователя с помощью следующей команды:

adduser sajid

Добавление нового пользователя в Debian

Добавление нового пользователя в Debian

Теперь добавьте только что созданного пользователя в группу sudo:

usermod -aG sudo sajid

Эта команда предоставит привилегии sudo пользователю sajid и позволит ему использовать команду sudo для выполнения административных привилегий.

Вы также можете проверить, был ли пользователь добавлен в группу sudo, используя следующую команду:

id sajid

Далее вы должны увидеть, что пользователь user1 принадлежит к двум группам: sajid и sudo.

uid=1002(sajid) gid=1002(sajid) groups=1002(sajid),27(sudo)

 Добавление нового пользователя в Debian

Добавление нового пользователя в Debian

Теперь переключите пользователя на user1 и выполните любую команду с помощью sudo:

su - sajid

sudo apt update

Ошибка Sudo Command Not Found в Debian исправлена

Ошибка Sudo Command Not Found в Debian исправлена

Заключение

Поздравляем!!!

Итак, вы теперь можете исправить ошибку sudo command not found на виртуальном частном сервере (VPS) в Debian 10. Наслаждайтесь.



03 Feb, 22



by Susith Nonis



4 min Read

How to fix "Sudo Command not found error" on Linux?

List of content you will read in this article:

  • 1. What is the Sudo command?
  • 2. What is a root user?
  • 3. Fixing Sudo command not found errors
  • 4. Conclusion

In Linux and UNIX-like systems, the Sudo command executes a specific command with root privileges. The user who runs this command has complete access to the system and can modify or add anything.

If you are an experienced Linux user, you might have encountered the “sudo: command not found” error while setting up the Linux desktop or virtual machine. Though you may have the command installed, you may get this error message in rare cases. However, this error message can be intimidating and prevents you from proceeding further with the setup process. As a result, it becomes obligatory to fix this error message.

Fortunately, we have a simple solution to this problem. Let us explore the solution in this article. But before it, let us have a brief introduction to the Sudo command.

What is the Sudo command?

Sudo stands for “Super User Do” and is pronounced as “sue dough.” It is a command-line utility that is usually built-in for UNIX and Linux-based operating systems and grants users permission to execute different commands at the most potent level of the system, the root level. It is generally used as a prefix for many other Linux commands, and only superusers have permission to execute them.

This command is equivalent to the “Run as Administrator” in Windows. Sudo also keeps a log of all commands and arguments.

What is a root user?

As there are several user accounts on the Linux system, many of them are assigned a set of privileges that do not have the right permissions to carry out administrative tasks. Also, users with limited privileges are not granted permission to access certain filesystem areas.

However, one user has the right to access any part or area of the system called the root user. The root user is the name given to a Linux user who can perform any operation on the machine without requiring permission from another user. The root user is also known as the Super User. This user’s user ID is 0.

It’s more powerful than Administrator in Windows, more akin to SYSTEM in Windows, and you can log into the system. The root user is in charge of creating new users and assigning various permissions on the machine. The command that must be run as a root user begins with Sudo.

Fixing Sudo command not found errors

Being a command, sudo is also a package that comes installed by default on the Linus systems. However, certain Linux distributions do not get sudo installed, and when you run the command on such systems, you receive the error message “sudo: command not found.”

Here is a solution that you can follow to fix the error:

  • Switch to the root user
  • Type in the following command to go to the root user mode

$ su -

  • Update the repositories using the following command

$ apt update

  • Run the following command on Debian-based distributions:

$ apt-get install sudo

  • The output will be something like this:

Reading package lists... Done
Building dependency tree     
Reading state information... Done
The following NEW packages will be installed:
 sudo
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/1,059 kB of archives.
After this operation, 4,699 kB of additional disk space will be used.
Get:1 http://security.debian.org/ squeeze/updates/main sudo amd64 1.7.4p4-2.squeeze.3 [610 kB]
Fetched 610 kB in 4s (132 kB/s)
Selecting previously unselected package sudo.
(Reading database ... 135532 files and directories currently installed.)
Unpacking sudo (from .../sudo_1.7.4p4-2.squeeze.3_amd64.deb) ...
Processing triggers for man-db ...

  • Run the following command on RHEL/CentOS/Fedora:

$ yum install sudo

  • Give all the sudo permissions using the following command

$ user od -AG <username>

  • Open the ‘sudoers’ file to check the permissions

$ nano /etc/sudoers

  • Check if the sudo has all the permissions associated.

# Full access for members of the sudo group
%sudo ALL=(ALL:ALL) ALL
# User privilege specification
root ALL=(ALL:ALL) ALL

  • You should now be able to run all the commands using sudo.

Conclusion

For security purposes, the Linux systems provide permissions only to the root user and the users allowed by the root user to perform administrative tasks. We hope the above solution will help you fix the error “sudo: command not found” on most Linux distributions.

Good Luck!

People also read: 

  • How to Create Sudo User in Debian 
  • How to use Sudo on Debian, FreeBSD, and CentOS

Recently, I deployed a Debian 10  managed VPS and noticed that I could not execute privileges tasks by invoking the sudo command. Instead, I got the error ‘sudo command not found in Debian 10′.  Turns out that the sudo command-line tool is not present by default. However, I managed to fix the problem in a few simple steps.  In this guide, we will show you how to resolve the ‘sudo command not found in Debian 10′.

To elaborate on the error I encountered, here’s a screenshot from the putty client console. As you can see, I couldn’t even update the package lists of my Debian system. As you would imagine, this can be a very frustrating experience.

sudo command not found Debian 10

Thankfully, this can be resolved in a few simple steps. The only thing that you need to do is to install the sudo command.  Let’s see how.

Step 1: Install the ‘sudo’ command

Installing sudo is quite a piece of cake. To achieve this, log in or switch to root user and use the APT package manager to update the system package list.

# apt update

Then install sudo as shown.

# apt get install sudo

Alternatively, you can concatenate these two commands:

# apt update && apt install sudo

When prompted to continue. hit ‘Y‘ to proceed.

Install sudo command on Debian 10

And that’s about it.  If you have a new or existing user, you need to add that user to the sudo group. In effect, this grants sudo privileges to the user, and this allows them to use the sudo command to perform administrative privileges.

Step 1: Add a regular user to the sudo group

To add the user to sudo group, use the usermod command as shown:

#  usermod -aG sudo username

For example, to grant a user ‘james’  administrative privileges, run:

#  usermod -aG sudo james

Grant a user sudo privileges

To confirm that the user has been added to the sudo group, use the id command as shown.

$ id james

confirm that a user is added to sudo group

From the output, you can clearly see that the user ‘james’ belongs to two groups: ‘james‘ and ‘sudo‘. Going forward, you can switch to the user and execute elevated tasks using the sudo command.

$ su james

$ sudo apt update

This brings a close to this topic. We do hope that you are now able to fix the ‘sudo command not found‘ issue. Thank you for taking your time and as always, your feedback is much appreciated.

About James

Hey there! This is James, a Linux administrator and a tech enthusiast. I love experimenting with various distributions of Linux and keeping tabs on what’s new in the Linux world.

Понравилась статья? Поделить с друзьями:
  • Bash raise error
  • Bash print error
  • Bash pipe error
  • Bash permission denied termux как исправить
  • Bash output error code