83

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 the instructions at this link: https://help.ubuntu.com/community/RootSudo

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.

migrated from serverfault.com Jan 19 '15 at 23:15

This question came from our site for system and network administrators.

  • 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 – Gravy Jan 19 '15 at 23:14
  • Same question was asked here too ? superuser.com/questions/866582/… – shubham Jan 20 '15 at 1: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 .... – Jonah Nov 6 '15 at 13:21
  • 2
    xkcd.com/838 – Revetahw Oct 16 '16 at 14:05
56

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" 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 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!

  • 14
    -1: cd - will not go to the home directory but to the most recent other directory. sudo - will not ask for your user password but for you root password. Do not edit /etc/sudoers manually use visudo for that. Typical ubuntu systems have no root password at all but rely completely on sudo. – michas Apr 1 '16 at 14:13
  • @michas You cannot use visudo without sudo in Debian. vi solution is also not possible because read-only. Gedit works in my case. – Léo Léopold Hertz 준영 Jun 8 '16 at 16:48
  • In debian 8 you can use vi without sudo as root. To write to the read-only file use :wq! – The Oracle Jul 27 '17 at 23:09
  • This also works for me, the great help indeed! – U2m Dec 7 '17 at 7:23
  • Thanks for your answer. But I am not even able to run su - – Vishal Aug 16 '18 at 9:44
40

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

https://askubuntu.com/questions/24006/how-do-i-reset-a-lost-administrative-password

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.

  • 1
    Sorry I forgot to mention that I resolved this problem a very long time ago. This is the solution to the issue I had and possibly anyone else may have. – fsolano94 Jun 24 '15 at 4:22
  • 3
    I still get the message after typing this as well as adduser NAME sudo. I think there m,ust be something else. I'm using Debian 7.8. – Tomáš Zato Oct 22 '15 at 9:03
  • This is not sufficient solution in Debian 8.5. ShrikantKhawale's proposal with little additions is the correct here. – Léo Léopold Hertz 준영 Jun 8 '16 at 16:49
  • 3
    @masi The trick above does work in Debian 8.5 (at least here), but only after you log out and back in again. – jcoppens Aug 12 '16 at 17:36
  • @jcoppens is right, works for Debian 8.6 too, only after log out and login – hello_earth Dec 30 '16 at 17:05
11

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.

  • 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 4 '16 at 16:27
4

Do this to reset the password for your admin user.

https://help.ubuntu.com/community/LostPassword

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?

  • I am programming Tetris in C and am using curses as a cross platform for graphical user interfacing. And yup I am going to follow the link – fsolano94 Jan 20 '15 at 0:04
4

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:)

  • Same issue on regular debian (9); manually editing /etc/sudoers did the trick – Zoe Jan 14 at 7:41
1

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
  • 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 2 '16 at 18:56
  • 1
    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 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".

-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

Not the answer you're looking for? Browse other questions tagged or ask your own question.