Linux нет команды sudo

Содержание
  1. How to fix «sudo command not found error» with examples [Update 2023]
  2. Why sudo is used in Linux before every command?
  3. How to fix sudo command not found error in Debian/Ubuntu like Distros
  4. Solution-1 Check and install sudo package
  5. Step1.1 List installed packages in Ubuntu and look for the «sudo» package
  6. Step1.2 Switch to root user
  7. Step1.3 Run apt command to install sudo package in Ubuntu/Debian
  8. Step1.4 Give sudo rights to your own user by adding it to the sudo group
  9. Step1.5 Verify your user is added to the sudo group
  10. Step1.6 Make sure your sudoers file have sudo group added
  11. Solution2 — Setup path variable to fix sudo command not found errors
  12. Step2.1 Switch to root user
  13. Step2.2 Run /usr/bin/sudo command to check whether it’s working or not
  14. Step2.3 Edit /etc/environment file and add » /usr/bin» directory in PATH
  15. Fix «sudo command not found error» in Fedora/AlmaLinux/Rocky Linux Distros
  16. Solution3- Install sudo and add user to «Wheel» group to fix sudo errors
  17. Step3.1 — Login with root user and check for sudo package installation
  18. Step3.2 Install sudo package
  19. Step3.3 Add user to the wheel group
  20. Step4.4 Check with the id command
  21. Frequently asked questions on sudo
  22. Q1: Why is sudo not working?
  23. Q2: How do I enable sudo?
  24. Q3: How do I find sudo commands?
  25. Q4: How do I fix sudo command not found Mac?
  26. Q5: Do I need to install sudo?
  27. Ending Note
  28. About The Author
  29. Dev
  30. Ошибка «-bash: sudo: command not found» — не найдена команда sudo (РЕШЕНО)
  31. 1. Вам не нужно указывать sudo
  32. 2. Используйте su вместо sudo
  33. 3. Установите sudo
  34. Как установить sudo в Debian и производные
  35. Как установить sudo в Arch Linux и производные

How to fix «sudo command not found error» with examples [Update 2023]

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?

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.

Читайте также:  Linux нет команды open

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.

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

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

Enter «root» password, when prompted.

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

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 —

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.

sudo commands help

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

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

Enter root user password, when asked.

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

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

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

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.

Читайте также:  Аудит операционной системы linux

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.

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

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

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.

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

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 —

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

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.

Читайте также:  Mysql linux посмотреть базы данных

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

4. Add your user as follows in sudoers file —

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.

About The Author

Dev

Hi, My Name is Dev and as an Information Technology professional, My Life revolves around Gadgets, Servers, Storage, Software, Operating system, Internet and Cloud computing. My philosophy is “being healthy” and follow your “passion or hobbies” to make your life interesting. Please feel free to contact me for any questions, feedback and suggestions.

Источник

Ошибка «-bash: sudo: command not found» — не найдена команда sudo (РЕШЕНО)

Утилита sudo позволяет выполнять команды от имени другого пользователя, обычно она используется для запуска утилит с повышенными правами от root.

При использовании sudo, например:

вы можете столкнуться с ошибкой:

-bash: sudo: command not found

Данная статья посвящена решению ошибки что команда sudo не найдена.

1. Вам не нужно указывать sudo

Если вы выполняете команды на сервере под пользователем root, то вы можете пропускать sudo, поскольку все команды в любом случае выполняются с повышенными привилегиями.

2. Используйте su вместо sudo

Для выполнение КОМАНДЫ от имени root используйте конструкцию:

Для открытия интерактивной оболочки с правами root выполните:

3. Установите sudo

Как установить sudo в Debian и производные

По умолчанию sudo не установлена в Debian, но вы можете установить её. Вначале включите режим su:

После этого вам может понадобиться настроить пользователей и разрешения. Дайте права на выполнения команд с Give sudo вашему собственному пользователю:

Убедитесь, что ваш файл sudoers имеет добавленную группу sudo. Для проверки и модификации файла sudoers запустите

и добавьте следующую строку (если она отсутствует):

# Разрешить членам группы sudo выполнять любые команды %sudo ALL=(ALL:ALL) ALL

Вам нужно повторно зайти или полностью перезагрузить компьютер чтобы изменения вступили в силу.

Для создания нового пользователя с sudo запустите команду вида:

sudo useradd -m -G sudo -s /bin/bash НОВЫЙ_ПОЛЬЗОВАТЕЛЬ

Замените НОВЫЙ_ПОЛЬЗОВАТЕЛЬ на желаемое имя.

Установите пароль для нового пользователя:

passwd НОВЫЙ_ПОЛЬЗОВАТЕЛЬ

Как установить sudo в Arch Linux и производные

Установка sudo:

В файле /etc/sudoers

найдите и раскомментируйте строку

чтобы разрешить членам группы wheel выполнять любые команды.

Для создания нового пользователя с sudo (замените НОВЫЙ_ПОЛЬЗОВАТЕЛЬ на настоящее имя) выполните команду вида::

sudo useradd -m -g users -G wheel,video -s /bin/bash НОВЫЙ_ПОЛЬЗОВАТЕЛЬ

Смотрите также:

Источник

Оцените статью
Adblock
detector