xtmci

How to add a user to the sudoers file in Linux

Sun May 3 6:34 pm EDT 2026

Key points

  • Open the /etc/sudoers file.
  • Add username ALL=(ALL:ALL) ALL at the end of the file.
  • Save and exit the file.

How to do it

The visudo command works with several editors available in the system. To designate a specific editor, use the command syntax like this:

EDITOR=editor_name visudo

For example, the following command opens the /etc/sudoers file in the vim editor:

EDITOR=vim visudo

Add the following line at the end of the file:

username ALL=(ALL:ALL) ALL

Save and exit the file.
Now, switch to the user account and run some testing commands:

su -l username
sudo apt update