151

I am running Ubuntu 12.04 on my laptop using VMware Player. I am not sure why but I have an account called "User Account" in addition to my account that I usually login to use Ubuntu. Well that was just a side comment but basically all I am trying to do is install the ncurses library on Ubuntu. I have tried installing ncurses using the following command lines:

sudo apt-get install libncurses5-dev
sudo apt-get install ncurses-dev

When I tried installing ncurses twice using the above commands I received the following prompt in the terminal:

[sudo] password for username

When I type in my password I receive the following message:

username is not in the sudoers file. This incident will be reported.

So far I have tried enabling the root user ("Super User") account by following these instructions.

Here are some of the things the link suggested to do:

Allow an other user to run sudo. Type the following in the command line:

sudo adduser username sudo

Or

sudo adduser username sudo

logging in as another user. Type the following in the command line:

sudo -i -u username

Enabling the root account. Type the following in the command line:

sudo -i

Or

sudo passwd root

I have tried all of the above command lines and after typing in each command I was prompted for my password. After I entered my password I received the same message as when I tried to install ncurses:

fsolano is not in the sudoers file. This incident will be reported.
Stephen Kitt
  • 434,908
fsolano94
  • 1,647
  • I don't have comment's yet so bare with me here... Question. is fsolano the first user you made with the install of ubuntu? usually that should have admin privileges, if you perform an admin function in a graphical sense does it work for you at all? IE if you open the GUi for user management and try to do something adminy does it work? or tell you you aren't root –  Jan 19 '15 at 23:14
  • 1
    Same question was asked here too ? http://superuser.com/questions/866582/username-is-not-in-the-sudoers-file-this-incident-will-be-reported/866600#866600 – shubham Jan 20 '15 at 01:37
  • if you've a root user with its password set , you can login root using su and add urself to sudo group àdduser username sudo else , you'll have to boot with live cd/usb and chroot to the installed system , it will log into root by default , set a root password for next cases passwd , and add yourself to sudo from there , and reboot , you'll have your username added to sudo and also you'll have root password , in case if sudo still not working , you can handle it .... – Yunus Nov 06 '15 at 13:21
  • 7
    https://xkcd.com/838/ – Fiksdal Oct 16 '16 at 14:05
  • I don't know if this is helpful but traditionally the group that is given sudo access is called "wheel". Get an account added to that group and they can usually use sudo. Maybe it's "sudo" in this case but that would be unusual so try wheel anyway if you can get root access or something. Usually the first account you created when installing your distro gets added to this group. So you may need to log into that account for access. Sudo itself has a lot of ways it can be configured so it's messages can be less than helpful. – davolfman Mar 01 '22 at 17:28

10 Answers10

115

When this happened to me all I had to do to fix it was:

Step 1. Open a terminal window, CTRL+ALT+T on my system (Debian KDE after setting up as hotkey)

Step 2. Entered root using command su root

Step 3. Input root password

Step 4. Input command apt-get install sudo -y to install sudo

Step 5. Add user to sudoers file by inputting adduser username sudo, put your username in place of username

Step 6. Set the correct permissions for sudoers file by inputting chmod 0440 /etc/sudoers

Step 7. Type exit and hit Enter until you close your terminal window. Shutdown your system completely and reboot.

Step 8. Open another terminal window.

Step 9. Try any sudo command to check if your username is correctly added to sudoers file. I used sudo echo "Hello World!". If your username has been correctly added to the sudoers list then you will get Hello World! as the terminal response!

SAMPro
  • 227
51

Follow the link to reset your admin password [sounds like you named your admin user account as user :)]

After that, login as the admin user and execute the following.

sudo usermod -aG sudo,adm fsolano

Now you can login as fsolano and you should be able to run sudo command.

If you get bash: usermod: command not found even as root, try:

/sbin/usermod -aG sudo,adm fsolano
Manuel Jordan
  • 1,728
  • 2
  • 16
  • 40
Arul
  • 885
  • 7
  • 8
27

I am having the same issue with Kali anytime I want to add newuser to the sudo group by typing this command:

usermod -aG sudo newuser

and editing the right section in /etc/sudoers. All crap!

My fix for this nonsense is to copy the line for root below it and changing root to newuser:

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

newuser ALL=(ALL:ALL) ALL

I remember the usual method with usermod used to work but is it a bug for the last couple of years now? it's really nonsense. anyway, if someone has a better answer, share it please:)

breadfan
  • 271
  • Same issue on regular debian (9); manually editing /etc/sudoers did the trick –  Jan 14 '19 at 07:41
  • indeed, seems to be a bug. The user is in the sudo group. It was uncommented in /etc/sudoers - however, it didn't work! Only when i manually added as you suggested, it started to work. Thanks! – user3804598 Nov 23 '19 at 18:55
17

The config file /etc/sudoers list, who is allowed to run which commands as which user.

On ubuntu this file contains a line allowing all users of the sudo group to run commands as the root user.

To check which users are in the sudo group you can type getent group sudo. You can also check the groups of your current user by typing id.

Probably your current user is not in the sudo group and is therefore not allowed to use the sudo command.

Log in as some sudo enabled user if you want to run sudo.

michas
  • 21,510
  • Well thats just the thing. I would login as the admin or root user but I forgot the password when I first installed Ubuntu on my machine. – fsolano94 Jan 19 '15 at 23:35
  • sudo:x:27:user (im not sure what the x or 27 is but I am positive that user is the user account that I do not know/remember the password to) – fsolano94 Jan 19 '15 at 23:40
  • @fsolano94, boot into some form of rescue environment (either directly, or booting from installation media), and change the root password. Or edit the /etc/sudoers file (preferrably using visudo(1)). – vonbrand Jan 04 '16 at 16:27
  • that is the problem. login as another user solves nothing – KansaiRobot Jul 10 '20 at 08:59
9

Follow the instructions to reset the password for your admin user:

Then you'll be able to grant sudo permission to your regular user with

sudo adduser username sudo

as you posted in your original question.

By the way: why are you installing ncurses? Are you compiling something?

Manuel Jordan
  • 1,728
  • 2
  • 16
  • 40
Andrew M.
  • 210
  • 1
  • 4
2

You can also add a user to sudo group for all access right by:

  1. Going to your root directory user by sudo su (ubuntu 16.04 LTS)
  2. Then enter your current user password
  3. type sudo adduser <username> sudo where username is the name of the user you want to add in the sudoers list
  4. For checking if your required user is added succesfully type getent group sudo which will show the list of sudo users
GnP
  • 2,345
  • 1
    Hi, welcome to Unix SE and congrats for a good first answer. I fixed your formatting a bit, you can learn more about that by clicking on "syntax help" when writing a post. – GnP Sep 02 '16 at 18:56
  • 2
    This is not a good answer. (1) The question states that sudo doesn’t work for the user.  (2) The answer sudo adduser <username> sudo has already been given. – G-Man Says 'Reinstate Monica' Nov 30 '17 at 16:22
0

If you have any other root/admin user than 'fsolano', that is not in the sudoers file. This incident will be reported:

check sudo enabled users (groups)
# getent group sudo 
sudo:x:27:xyz,abc 

since the user 'fsolano' is changed to standard user and if you have any other root privileged user, login via the root one and change 'fsolano' to administrator using "User Accounts".

Anthon
  • 79,293
Dovegg
  • 1
0

Try the following command

su root -l -c "echo 'ismail ALL=(ALL)  ALL' >> /etc/sudoers"

However, I found a better solution.

su root -l -c "adduser ismail sudo"

replace ismail with your user name.

You have to restart the machine after running this command.

Ahmad Ismail
  • 2,678
-1

The simplest way to add an user to sudoers file is run the command bellow as user with permission to execute gpasswd:

sudo gpasswd -a username sudo
-2

1.You can check whether you are a part of sudo group or not by using below command

groups username ===> it will lists the groups for which he belongs too

We can check by below script too

h=`groups username| awk -F ":" '{print $2}'| grep -io 'sudo'`
if [[ $h == "sudo" ]]
then
echo "user praveen is part of group sudo"
else
echo "Need to add user to group sudo"
echo "Swictch to root and add user"
fi