To add the user myuser
to the sudoers
group and configure it so that the user doesn’t get prompted for a password when executing sudo
commands, follow these steps:
1. Add devel
to the sudo
group
Run the following command as a user with administrative privileges (or root):
1 |
sudo usermod -aG sudo myuser |
This adds the myuser
user to the sudo
group, granting it administrative privileges.
2. Configure sudoers
to disable the password prompt
Edit the sudoers
file to specify that myuser
can use sudo
without being prompted for a password. Use visudo
, which ensures the file syntax is correct before saving:
1 |
sudo visudo |
Add the following line to the file:
1 |
myuser ALL=(ALL) NOPASSWD:ALL |
This line specifies that the devel
user can run all commands as any user (including root) without providing a password.
3. Verify the configuration
Save and exit the visudo
editor (usually by pressing Ctrl+X
, then Y
, then Enter
). To test:
- Switch to the
myuser
user:su - myuser
- Run a command with
sudo
:sudo whoami
The output should be:root
No password prompt should appear.
Notes
- Be cautious with this configuration, as it allows the
myuser
user to execute any command withsudo
without restriction. Use it only if you trust the user and for specific use cases like automation or scripts. - If you only want to allow specific commands to run without a password, replace
ALL
in theNOPASSWD
directive with a list of commands. For example;myuser ALL=(ALL) NOPASSWD:/usr/bin/systemctl,/usr/bin/apt
This setup is now complete.