Is not in sudoers file debian как исправить

After logging into ssh, I got this message:

‘Username’ is not in the sudoers file. This incident will be reported.

How can I resolve this? I’m connecting ssh to my virtual private server.

Promise Preston's user avatar

asked Dec 14, 2017 at 5:43

Danish Arman's user avatar

3

Open file

su root 
nano /etc/sudoers

Then add the user below admin user like below syntax.

user_name ALL=(ALL)  ALL

answered Dec 14, 2017 at 6:20

sanath meti's user avatar

sanath metisanath meti

4,8491 gold badge21 silver badges30 bronze badges

11

Both the above answers are correct as far as they go but it is easier to add your user to the sudo group in debian based systems (Ubuntu, kbuntu, debian, etc) and the wheel group under RedHat based systems (RedHat, Fedora, CentOS, etc)

usermod -a -G sudo user
or
usermod -a -G wheel user 

answered Dec 14, 2017 at 10:13

Rodney Howard's user avatar

7

This is a very common error for the beginners.
The error occurs because we are trying to access/update something with super privileges from the user instead of root -user.

Hence, to solve this,we need to make changes in the sudoers file where the root user has been given the privileges. So, switch to root user,run the following command

sudo su 
# vi /etc/sudoers

The editor would open the file, now scroll down to the bottom where you will see a line

#User privilege specification

root     ALL=(ALL:ALL) ALL

username ALL=(ALL:ALL) ALL

As you can see, I have just added my username with all permissions.

Save the file, and exit. Switch back to the user and start using sudo commands with ease.

answered Jul 20, 2019 at 12:12

Sonal 's user avatar

Sonal Sonal

5795 silver badges7 bronze badges

3

At the top of the aforementioned /etc/sudoers file there’s an info:

"## This file MUST be edited with the 'visudo' command as root."

In order of doing as we’re told, use:

$ su
> Enter root password: *******
$ visudo -f /etc/sudoers

Find the following section of /etc/sudoers file and add your users privileges:

# User privilege specification
root    ALL=(ALL:ALL) ALL
user_name ALL=(ALL) ALL

Save the file (press esc and type :x if vim is your default text editor, for nano press ctrl+o, enter and then ctrl+x).

Type exit to turn off the root shell, and enjoy the power of sudo with your username

answered Dec 9, 2019 at 20:06

wscourge's user avatar

wscourgewscourge

10.4k14 gold badges57 silver badges79 bronze badges

You should use visudo to edit /etc/sudoers file.

Just run
sudo visudo -f /etc/sudoers

and add your username with correct syntax and access rights.
You can find more in man sudoers

snowpeak's user avatar

snowpeak

7689 silver badges25 bronze badges

answered Dec 14, 2017 at 9:39

Viktor Khilin's user avatar

Got a slightly different syntax to Rodney’s from my host

usermod -aG wheel username

Their explanation was

The user will need to be added to the wheel group.

Use the usermod command to add the user to the wheel group.

You may need to log off and log back in after doing this

answered Jul 5, 2018 at 15:41

Robert Sinclair's user avatar

Robert SinclairRobert Sinclair

4,4602 gold badges41 silver badges44 bronze badges

3

If you’re unable to find visudo on your system

whereis visudo

Launch this tool

./PATH/visudo

add this line under

User privilege specification

user_name ALL=(ALL)  ALL

Save the changes and here you go !

answered May 11, 2020 at 12:19

Olivier D'Ancona's user avatar

Olivier D’AnconaOlivier D’Ancona

7402 gold badges14 silver badges29 bronze badges

  1. Entered Root using command $ su root. Input Root Password

  2. Install sudo: $ apt-get install sudo -y

  3. Add your < username> $ adduser <username> sudo

  4. $ exit

  5. Then sign up and sign in the < username> session

  6. Finally, check with: < username>@< hostname>:~$ sudo apt-get update

answered Jun 13, 2019 at 19:20

Braian Coronel's user avatar

Braian CoronelBraian Coronel

21.8k4 gold badges55 silver badges60 bronze badges

1

try this video, it works for me.

  1. ssh root@localhost
  2. sudo vi /etc/sudoers
  3. insert username in file ‘sudoers’
  4. save and exit ssh

Dharman's user avatar

Dharman

30.3k22 gold badges84 silver badges132 bronze badges

answered Dec 30, 2020 at 3:35

user6670135's user avatar

First, switch/ log into the root user account or an account that has sudo privileges.

Next add the user to the group for sudo users:

  • If you’re on Ubuntu members of the sudo group are granted with sudo privileges, so you can use this:

    sudo adduser username sudo
    
  • If you’re on CentOS members of the wheel group are granted with sudo privileges, so you can use this::

    usermod -aG wheel username
    

Note: Replace username with your desired username.

To test the sudo access, log into the account that you just added to the sudo users grouP, and then run the command below using sudo:

sudo whoami

You will be prompted to enter the password. If the user have sudo access, the output will be:

root

If you get an error saying user is not in the sudoers file, it means that the user doesn’t have sudo privileges yet.

That’s all.

I hope this helps

answered Sep 18, 2020 at 14:34

Promise Preston's user avatar

Promise PrestonPromise Preston

22.7k12 gold badges136 silver badges139 bronze badges

Add your user to the list of sudoers. This will make it easier to execute
commands as the user that you have created will require admin privileges.

sudo adduser username sudo

(Note:- Username is the user you want to give the privileges)

answered Apr 15, 2020 at 4:35

Tej's user avatar

1

После установки пользователи в дистрибутиве Debian могут столкнуться с ошибкой not in the sudoers file. Как из возможных вариантов, при работе в терминале. Она возникает из-за того, что ваш пользователь не добавлен в файле sudoers. В связи с этим, при попытке использовать sudo, то есть, выполнить какое-то действие от имени суперпользователя, и возникает такая ситуация. Исправить ситуация с not in the sudoers file довольно просто, достаточно добавить имя вашего пользователя в файл sudoers, который находится в каталоге etc. Подробнее про каталоги в дистрибутивах Linux вы можете прочесть перейдя по этой ссылке.

По исправлению ошибки not in the sudoers file в Debian на каналах Дзен, Youtube и в ВК есть видео. Но иногда гораздо удобнее найти ответ в тексте.

Как уже говорилось выше, для исправления ошибки not in the sudoers file необходимо вписать имя вашего пользователя в файл sudoers. Открываем терминал, вводим команду:

su -

Тем самым получаем права суперпользователя, далее при помощи текстового редактора Nano произведем редактирование файла:

nano /etc/sudoers

В открывшемся файле ищем строку “root ALL=(ALL:ALL) ALL”, и под ней вписываем имя вашего пользователя, после чего задаем вашему пользователю такие же параметры, что и у root. К примеру, возьмем имя пользователя “cyber-x”, строка будет выглядеть следующим образом:

cyber-x ALL=(ALL:ALL) ALL

ошибку not in the sudoers file в дистрибутиве Debian

Сохраняем наши правки комбинацией клавиш “ctrl o” и закрываем текстовый редактор Nano “ctrl x”. Подробнее о работе с текстовым редактором читайте тут.

Теперь у вашего пользователя есть все необходимое, что бы использовать sudo, а соответственно, ошибка not in the sudoers file должна изчезнуть. Что бы выйти из root, который мы получили введя “su -“, достаточно в терминале набрать команду “exit”:

ошибку not in the sudoers file в дистрибутиве Debian 2

Заключение

Ошибка not in the sudoers file возникает частенько и не зависит от окружения рабочего стола. Что бы избежать not in the sudoers file, достаточно при установке Debian, не задавать пароль для супер пользователя:

ошибку not in the sudoers file в дистрибутиве Debian 3

А на этом сегодня все, если статья оказалась вам полезна, подписывайтесь на рассылку журнала в pdf формате, а так же на социальные сети журнала Cyber-X:

YouTube
ВКонтакте
Telegram

По вопросам работы сайта, сотрудничества, а так же по иным возникшим вопросам пишите на E-Mail. Если вам нравится журнал и вы хотите отблагодарить за труды, вы можете перечислить донат на развитие проекта.

С уважением, редакция журнала Cyber-X

Это краткое руководство по устранению проблемы «user is not in the sudoers file in Linux» в Linux/UNIX. Проблема вызвана тем, что пользователь не имеет доступа sudo в вашей системе и может быть быстро исправлена путем добавления пользователя в группу wheel с помощью команды usermod или путем редактирования файла sudoers в вашей системе Linux.

В этом руководстве я собираюсь показать вам два быстрых метода решения проблемы «user is not in the sudoers file in Linux», чтобы дать вашему пользователю доступ к sudo.

Способ 1: Использование команды usermod

Сначала узнайте, какое у вас имя пользователя, открыв терминал и выполнив приведенную ниже команду. Пропустите этот шаг, если вы уже знаете свое имя пользователя.

Переключите пользователя на root с помощью команды su:

Добавьте своего пользователя в группу wheel, выполнив следующую команду. Замените <username> на имя пользователя, указанное в шаге 1 выше.

sudo usermod -aG wheel [имя пользователя]

Выйдите из системы и войдите в нее (или перезагрузите), чтобы изменения вступили в силу. Проверьте, входит ли ваш пользователь в группу wheel, выполнив в терминале команду:

Теперь ваш пользователь может выполнять команды, требующие повышения прав, с помощью sudo в Linux без проблем.

Метод 2: Использование файла sudoers

Этот метод исправит проблему «пользователь отсутствует в файле sudoers» путем редактирования файла /etc/sudoers.

Сначала переключите пользователя на root с помощью команды su. Введите пароль root, когда появится запрос.

Отредактируйте файл sudoers, используя редактор vi или любой другой удобный для вас редактор.

либо

Прокрутите вниз, пока не найдете root ALL=(ALL) ALL и добавьте следующую строку под ним. Замените <имя пользователя> на ваше настоящее имя пользователя.

[ваше имя пользователя] ALL=(ALL) ALL

Вот как должен выглядеть ваш файл sudoers.

sudoers

Сохраните и выйдите из файла. Выйдите из системы и снова войдите в нее (или перезагрузите), чтобы изменения вступили в силу.

Теперь вы сможете выполнять команды с sudo в Linux/UNIX без каких-либо проблем. Это руководство было протестировано на нескольких других дистрибутивах Linux (Debian, Ubuntu, Arch), а также в UNIX (FreeBSD).

Вот и все. Вот как исправить ошибку «пользователя нет в файле sudoers» в Linux. Надеюсь, вы нашли этот пост полезным.

This article explains how to «fix» sudo not working on Linux, resulting in this message when trying to use it: «your-username is not in the sudoers file. This incident will be reported.» on Debian (and Debian-based Linux distributions like Ubuntu). sudo allows system admins to execute commands as root (administrator) or another user.

Example from a fresh Debian 10 (10.1) Buster installation on which sudo doesn’t work:

$ sudo apt update
[sudo] password for logix:
logix is not in the sudoers file.  This incident will be reported.

sudo doesn’t work by default on a Fresh Debian installation because your username is not automatically added to the sudo group (it does work on Ubuntu by default). But you may also see this if you created a new user but you forgot to add it to the sudo group, or if another user from your system removed the username from the sudo group.

You can check if the currently logged in user belongs to the sudo group by using the groups command. If the groups command does not return sudo on Debian-based Linux distributions, then that username can’t run commands with sudo. Example with output of a Debian user that’s not in the sudo group:

$ groups
logix cdrom floppy audio dip video pugdev netdev scanner lpadmin

You might like: How To Install The Latest Firefox (Non-ESR) On Debian 10 Buster (Stable) Or Bullseye (Testing)

The solution to this is to add that user to the sudo group. But how do you get root in that case, since you can’t modify or add users as a regular user? Use su - (or sudo su -), then add the user to the sudo group.

So to get root, then add your user to the sudo group, use:

su -
usermod -aG sudo YOUR_USERNAME
exit

Where:

  • su switches to the root user, while - runs a login shell so things like /etc/profile, .bashrc, and so on are executed (this way commands like usermod will be in your $PATH, so you don’t have to type the full path to the executable). You may also use sudo su - instead of su -
  • You need to replace YOUR_USERNAME with the username that you want to add to the sudo group.
  • I have used usermode to add a group to an existing user because it should work on any Linux distribution. adduser or useradd can also be used for this (adduser USERNAME -G sudo) but they may not work across all Linux distributions. Even though this article is for Debian, I wanted to make it possible to use this on other Linux distributions as well (I noticed that adduser doesn’t work on Solus OS for example).
  • exit exists the root shell, so you can run commands as a regular user again.

After this, sudo still won’t work! You will need to logout from that user, then relogin, and sudo will work.

This fixes the «Username is not in the sudoers file.  This incident will be reported» issue on your Debian machine, but you may run into another problem in some cases — sudo might not be installed at all by default. This is the case for example on a minimal Debian installation. In that case you’ll see an error like this when trying to run a command with sudo:

$ sudo apt update
bash: sudo: command not found

In that case, install sudo on Debian like this:

su - #or 'sudo su -'
apt install sudo
exit

A few more Debian-related articles you might like:

  • How To Downgrade Packages To A Specific Version With Apt In Debian, Ubuntu Or Linux Mint
  • How To Show A History Of Installed, Upgraded Or Removed Packages In Debian, Ubuntu or Linux Mint [dpkg]
  • How To List All Packages In A Repository On Ubuntu, Debian Or Linux Mint [APT]
  • How To Find The Package That Provides A File (Installed Or Not) On Ubuntu, Debian Or Linux Mint

Not every command on Linux is accessible to all users. Some functionality on this operating system has been restricted only to people with root access. A root user can access all the files/folders, including the system’s files. The root user can make major internal changes to the system that a regular account is not authorized to. The “sudo” keyword is utilized in Ubuntu to get the root user’s privileges. While attempting to use this keyword, an error may arise with the statement “User is not in the sudoers file”.

This article will explain why this particular error occurs and what steps anyone can take to resolve this issue.

Methods to Resolve “User is not in the sudoers file” Problem

There exist various causes that can cause this error to be invoked. The following post elaborates in great detail on all the causes and fixes. Before we get to the reasons and their solutions, we must ensure that the root is set to read and write. For this purpose, follow these steps.

Enter the GNU Grub Version of your Ubuntu Operating system by restarting the computer and clicking the shift key. GNU will easily give us access to the root shell so that we can make all the necessary changes to the system to remove this error. The following screen will pop up. Select “Advanced options” and press Enter:

The next step is select the kernel in recovery mode and press enter as shown below:

Once the recovery menu opens up, scroll to the root option as shown below, and press enter as demonstrated:

Press Enter again for maintenance and run the following command:

# mount -o rw,remount /

This command will allow you to be able to make system changes using commands.

Reason 1: The User Doesn’t Exist in the Sudo group

This error is invoked when the user tries to use the “sudo” command but that user is not in the sudo group. This leaves the user not capable of accessing a lot of the root user privileges. The snippet below visualizes the error:

Solution: Insert User into Sudo Group

The resolution to this problem is not complex at all. You simply add the user to the sudo group again. This can be achieved using the command below:

# adduser user sudo

In the code shown above, the “user” represents the username of the user that you intend to insert. Following the syntax, the below-stated command will add the user “itslinuxfoss” to the sudoers group:

# adduser itslinuxfoss sudo

By doing so, the user can be added to the sudoers file.

Reason 2: The User does not have Sudo Privilege

The possibility exists that the /etc/sudoers file was changed. This change could have been to revoke some privileges from the current user.

Solution: Give the User Sudo Privilege

The best fix to this issue is to grant that user sudo privileges once again. To achieve this, open up the file with this command:

# visudo

Add the following line to the file:

#includedir /etc/sudoers.d

The addition of this is demonstrated below:

This should grant Sudo access to the user once again.

Reason 3: Wrong Permissions for /etc/sudoers File

Files are often assigned permissions based on their functionalities. Not all files are capable of reading and writing. A few can write, whereas others are only capable of reading. The sudoers file needs to have read permission so that the system can read from the file. If this is not the case, then the system will be unable to find the user in the sudoers file.

Solution: Assign 0440 Permission to Sudoers File

The best way to resolve this error is to set the sudoers file permission to 0440. This is the permission code for giving the root access to read-only read as compared to the 0777 permission, which would grant write permissions as well, which we do not need. The “44” represents that the owner and group have read rights. To assign this permission, run the command shown below:

# chmod 0440 /etc/sudoers

Once you have executed all the required commands, you need to exit the recovery mode properly. To do this, run the command below:

# exit

Press enter on the “resume” option, and this will reboot your system. After the system is rebooted fully, use sudo with the current user.

Conclusion

Statement “User is not in the sudoers file” occurs due to 3 very common reasons. The user is not part of the sudo group, it is not allowed sudo privileges, or the sudoers file is not readable. These issues can be resolved by adding the user to the sudo group and granting it sudo privileges. Furthermore, the sudoers file can be assigned the 0440 permission, which allows it to be readable. This article has provided an in-depth guide on the reasons and solutions to fix the error “user is not in sudoers file”.

Понравилась статья? Поделить с друзьями:
  • Css class с как исправить
  • Как найти относительную плотность по воздуху формула
  • Как найти начальную цену товара
  • Как найти всех богов эгейского моря
  • Как найти свойства параметры