I had this issue for my Ubuntu and Pidora, so in this article you can have both solutions:
The problem I had was to add a user on an Ubuntu 14.04 at my work, so that someone else from the company can help me do some basic maintenance of the system (it was requested by my employee!), so this is how I did it after creating a user (new_user):
gpasswd -a new_user sudo
This command will add the user new_user to the group sudo.
I was working with Pidora (which is a Fedora remix for Raspberry Pi) and I was about to run a command using sudo that I faced the following error:
[NixSOS@pidora ~]$ sudo iptables -L -n
[sudo] password for NixSOS:
NixSOS is not in the sudoers file. This incident will be reported.
and I was confused for a while and then I searched for a way to add my user in the “sudoers file” and I’m going to explain how to add a user or a group to sudoers file. This should work all major linux distributions.
Before everything I should mention that in order to perform this action we should act as root user and we should be extra careful.
Follow these steps:
- Open a terminal (if you haven’t already)
- Login as root user:
- You will be asked to type root password and you should type it (mind that you may not see the password you are typing, but continue typing and at the end press
- Use the following command to edit sudoers file
- The sudoers file will open in Vim editor. at this point we should navigate to the end of the file either by arrow keys or by pressing
j(you can see the Vim cheatsheet here or here)
- Enter the “insert mode” by pressing
- Append the following line to add a user in the sudoers file (replace NixSOS with your desired username):
NixSOS ALL=(ALL) ALL
- Or append the following line to add a group in the sudoers file (replace NixSOSGroup with your desired group name):
%NixSOSGroup ALL=(ALL) ALL
Escbutton from keyboard to exit the “insert mode” of Vim
- Start type the following without pressing any extra keys and then press
- If you have done correctly you will not see any error, but in case of error, you will see the following:
>>> /etc/sudoers: syntax error near line 101 <<<
and then you should type
to proceed editing your file again (from step 5 of this tutorial) and correct your mistake.
- If everything went correctly and you didn’t see any error, type the following to exit the root user:
Now you should be able to use sudo for your user or group.