Score:0

Adding a User from the Command Line: is not in the sudoers file. This incident will be reported

bs flag

I usually work as root، no problem. But some recommend that to work as user (For security reasons). But they do not mention what problems you will face in this case.

These are the things I did.

I tried to create a username with adduser.

adduser USERNAME
su USERNAME
sudo true

And then I got this message:

sudo: unable to resolve host localhost: Name or service not known
[sudo] password for USERNAME:
USERNAME is not in the sudoers file.  This incident will be reported.

In the last step, you may have noticed a warning: sudo: unable to resolve host localhost: Name or service not known To fix this, I entered this command:

echo "127.0.0.1 localhost.localdomain localhost" > /etc/hosts

And it worked. Then I used this for the second message:

adduser USERNAME sudo
Adding user `USERNAME' to group `sudo' ...
Adding user USERNAME to group sudo
Done.

The problem must have been solved. right!?

su USERNAME
cd
sudo true
[sudo] password for USERNAME:
USERNAME is not in the sudoers file.  This incident will be reported.

But as you can see, the problem was not solved with the second message

adduser USERNAME sudo
The user `USERNAME' is already a member of `sudo'.

Now how do I solve this problem?

hr flag
What is your Ubuntu version? it would be unusual for `localhost` not to already be in the `/etc/hosts` file so I wonder if your system has other non-Ubuntu features (such as group specification `%sudo` not actually being in the `sudoers` file)
user487583 avatar
bs flag
@steeldriver Impish Idri it is there
user487583 avatar
bs flag
@user535733 You know what's funny, this is even better than the released version, because I was getting three error messages there in 20.04.2. But here are just two of them.
terdon avatar
cn flag
Note that `echo "127.0.0.1 localhost.localdomain localhost" > /etc/hosts` has just removed anything that was in your `/etc/hosts` file and replaced it with `127.0.0.1 localhost.localdomain localhost`. That may or may not be a problem.
user487583 avatar
bs flag
@terdon maybe next time I will change it with ```nano```.
user487583 avatar
bs flag
@karel Not exactly, there are other things that are mentioned, some of which are completely unrelated to this issue. Some of them may corrupt the whole system!.
user487583 avatar
bs flag
@terdon I reinstalled and checked it was completely empty. So there was nothing in it to be removed.
Score:2
cn flag

You will need to edit the sudoers file at /etc/sudoers, but make sure to do this using the command visudo and never edit that file directly since any mistake can break the sudo settings. You can refer to the following link for more info on the syntax for the sudoers file: https://www.hostinger.com/tutorials/sudo-and-the-sudoers-file/amp

user487583 avatar
bs flag
I thought there should be a change in the sudoers file , But I'm not sure exactly what this change should be. I do not want to make the wrong change and make the situation worse than it is
Gagan avatar
cn flag
If you want the user to have full root permissions after providing the sudo password, add something like this: username ALL=(ALL)
user487583 avatar
bs flag
Ok, I think I should use vim. (I do not know if it is possible with nano).
hr flag
@ubunShitu you should always use `visudo` to edit the sudoer(s) files. You can specify which editor it uses via the `EDITOR` environment variable ex. `EDITOR=nano visudo`
user487583 avatar
bs flag
@steeldriver I added this ```# User privilege specification root ALL=(ALL:ALL) ALL USERNAME ALL=(ALL:ALL) ALL ``` with ```nano /etc/sudoers``` and the problem was solved.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.