To grant a user sudo permissions, you can follow these steps:
Step 1: Open the sudoers file
You need to edit the sudoers file using the visudo command, which safely edits the file and checks for syntax errors:
sudo visudo
Step 2: Add the user to the sudoers file
In the sudoers file, you can add a line to grant sudo privileges to the user. For example, to grant sudo access to a user named username, add the following line:
username ALL=(ALL) ALL
This line means that the user username can run any command as any user on the system.
Step 3: Save and exit
After adding the line, save the changes and exit the editor. In visudo, you typically save by pressing Ctrl + X, then Y to confirm changes, and Enter to exit.
Alternative Method: Add User to the sudo Group
Another way to grant sudo permissions is to add the user to the sudo group:
sudo usermod -aG sudo username
Replace username with the name of the user you want to grant sudo permissions.
Verify
To verify that the user has been granted sudo permissions, you can switch to that user and run:
sudo whoami
If the setup is correct, it should return root.
