Ubuntu 20.04. I have created 2nd user and try to do:

sudo su [sudo] password for xoleg: xoleg is not in the sudoers file. This incident will be reported. xoleg@oleg-HP-2004:~$

Then my other user added this 2nd user

>usermod -aG sudo xoleg

and yet this

>nano /etc/sudoers

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL
# added this
username ALl=(ALL) NOPASSWD:/bin/mkdir,/bin/rmdir

after it again to xoleg session

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

Where am I wrong? how to fix it?

  • 2
    Have you logged out and back in after adding the user to the group?
    – Raffa
    Jun 21 at 14:14
  • No, should this new added user logout/login?
    – ZedZip
    Jun 21 at 14:23
  • Yes, ... Please see askubuntu.com/a/1468587
    – Raffa
    Jun 21 at 14:24

1 Answer 1


This solution worked for me in Ubuntu 22.04. To get sudo access, switch to root first using:

su root

Enter your password when prompted, and then add user to sudo:

adduser username sudo

Enter your user name in place of username above, now switch back to current user again:

su username

That's all. Try to run sudo again with your user. I hope this solves your problem.

  • 2
    Once you do the su and adduser just have the user log out and log in again, it'll solve the sudo problem. Because that's the proper way to refresh perms.
    – Thomas Ward
    Jul 29 at 20:16
  • Yes, that also works. But if someone does not want to logout and login again then just su username works fine.
    – CMB
    Jul 29 at 20:18
  • 1
    That's disadvised, until you exit out of su root because then you can just run exit and end up at a root prompt again. It's extremely insecure, so you need to make sure the user exits after they are done with root, then they can run su username and enter their password otherwise they're in a root prompt easily via the execution trees and you do not want users to stay in root prompts.
    – Thomas Ward
    Jul 29 at 20:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .