Granting sudo access to a user on a Debian system allows them to execute commands with superuser privileges, essential for performing administrative tasks. This guide will walk you through the steps to create a new user and configure sudo access.
sudo is not installed, switch to the root user with su and install it.
sudo (if not installed)If sudo is not installed, switch to the root user:
suThen install sudo using the following command:
apt update && apt install sudoIf you haven’t created a new user yet, use the following command, replacing username with your desired username:
sudo adduser usernameYou will be prompted to set a password and enter optional user information.
sudo GroupTo grant the new user sudo privileges, add them to the sudo group with:
sudo usermod -aG sudo usernameThe -aG option appends the user to the specified group without removing them from other groups.
sudo AccessTo check if the user has been added to the sudo group, run:
groups usernameYou should see sudo listed among the user’s groups.
sudo AccessSwitch to the new user account:
su - usernameTest sudo access by executing a command that requires superuser privileges:
sudo apt updateYou will be prompted to enter the user's password. If set up correctly, the command should execute without errors.
sudoers File (Optional)If you need to customize sudo permissions, edit the /etc/sudoers file using the visudo command, which checks for syntax errors:
sudo visudoTo grant the user full sudo privileges, add the following line:
username ALL=(ALL:ALL) ALLReplace username with the actual username.