Sửa lỗi "USERNAME is not in the sudoers file. This incident will be reported" trong Debian

This article explains how to "fix" sudo not working on Linux, resulting in this message when trying to use it: "your-username is not in the sudoers file. This incident will be reported." on Debian (and Debian-based Linux distributions like Ubuntu). The solution 1 here is:

su -
usermod -aG sudo YOUR_USERNAME
exit

The solution 2 here is:

  • First, switch user to root using the su command. Type your root password when prompted: su
  • Edit the sudoers file using the vi editor or any other editor you are comfortable with: visudo
  • Scroll down until you find root ALL=(ALL) ALL and add the following line below it. Replace with your actual user name.
    <your username> ALL=(ALL) ALL
    
  • Log out and back in (or reboot) the system for the change to take effect.