(From remote Debian server) When you give sudo right with visudo for the first time on first boot to a new user, su - <newuser> will not be enough to offer the right to use sudo and then reboot the server is the way to get the right to use the sudo command.

Then you get back:

[sudo] password for <newuser>: 
<newuser> is not in the sudoers file.  This incident will be reported.

I have tried service sudo restart but that does not make the trick

:~$ getent group sudo
:~$ sudo bash
[sudo] password for <newuser>: 
<newuser> is not in the sudoers file.  This incident will be reported.

Do you think there is an efficient way to do that?

Information on configuration: Debian wheezy

EDITOR=vim visudo

uncommented: sudo ALL=(ALL:ALL) ALL

gpasswd -a <newuser> sudo

closed as off-topic by Jeff Schaller, MelBurslan, Archemar, Stephen Kitt, garethTheRed May 17 '16 at 18:13

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Jeff Schaller, MelBurslan, Archemar, Stephen Kitt, garethTheRed
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    I've never had to reboot to add sudo privileges. Perhaps you have a typo for "sudo ALL..." where it should be "%sudo ALL ..." ? – Jeff Schaller May 12 '16 at 16:51
  • I always need to reboot. @JeffSchaller – aurelien May 12 '16 at 16:59
  • 1
    @aurelien, in that case there is something wrong with your system. sudo should never need rebooting after installation – MelBurslan May 12 '16 at 17:10
  • It is a fresh installed system, and first thing I have do is to create the sudo. And for the moment I have not restarted it to try to understand that trouble @MelBurslan – aurelien May 12 '16 at 18:01
  • @JeffSchaller had it. %sudo does not comment out the line, it specifies that you're looking for the group sudo. Without the %, it's instead looking for a user named sudo which doesn't exist. No idea why a reboot would change that though. – mkomarinski May 17 '16 at 13:17

You do not need to reboot, but you do need to log out and back in which a reboot forces you to do. Your group membership isn't dynamically updated, so if you add yourself to the sudo group you won't be a member of the group until the next time you log in.

  • How do you log out from remote terminal? exit does not make the trick – aurelien May 12 '16 at 17:57
  • With the system still running, disconnect from all sessions (if you're logged in via SSH, exit or logout). Open a brand new shell as the user you want to use sudo as. You can now examine your group membership using id and verify you're in the sudo group. At this point, you should be able to use sudo. – mkomarinski May 12 '16 at 18:21
  • bash: logout: not login shell: use `exit' so no and as always explain exit from remote does not logout but cut the connection. and about the id I have explain that :~$ getent group sudo sudo:x:27:<newuser> so the newuser is already in the group, but nothing happen. So no that does not make the trick @mkomarinski – aurelien May 12 '16 at 18:29
  • :~$ id uid=1000(newuser) gid=1000(newuser) groups=1000(newuser),27(sudo) which give the same back as the getent – aurelien May 12 '16 at 18:31
  • 1
    That's the core of your problem, you need to completely disconnect from the remote server and then log back in as the user. Using id will tell you what your current group memberships are from the shell and will be more accurate than using getent – mkomarinski May 12 '16 at 18:32


# echo "<newuser>  ALL=(ALL) ALL" >> /etc/sudoers

Cf: https://www.debian.org/doc/manuals/debian-reference/ch01.en.html#_sudo_configuration

And personnaly I would use:

# tee -a "<newuser>  ALL=(ALL) ALL" >> /etc/sudoers

tee -a present the advantage of merge stuff to the existant without removing the old stuff

  • That does solve the issue, but it only applies sudo privileges to the specific user. For a system with only a few users this would be okay, but in an environment where there may be a larger number of administrators and they change periodically it becomes a bit harder to manage. – mkomarinski May 17 '16 at 13:18
  • There is no way to log out remote server. Exit just cut the ssh connection, it does not offer you a way to login. This is only possible on a Virtual Machine! – aurelien May 19 '16 at 11:43
  • About the point of larger number of administrators: Well, the situation is about a newly installed remote server where you login for the first time and install sudo. – aurelien May 19 '16 at 11:45

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