
Creating a sudo user improves security by allowing you to perform administrative tasks without logging in as the root user. It helps reduce the risk of accidental system wide changes and improves auditing capabilities. By assigning sudo privileges to specific users, you can also achieve finer grained permission management and control who can perform administrative operations.
This article explains how to create a sudo user on multiple distributions, including Ubuntu, Debian, and FreeBSD.
Prerequisites
Before you begin, you need to:
- Have access to a Linux server as a root or non-root user with sudo privileges.
Follow the steps below to create a new user and give them sudo privileges.
Create a new user. Replace
johnwith your desired username.console$ sudo adduser john
When prompted, enter a password for the user and other additional information such as full name or phone number.
Add the new user to the
sudogroup to grantsudoprivileges.console$ sudo usermod -aG sudo john
Switch to the newly created user account.
console$ sudo su - john
Run a
sudocommand to confirm that the user hassudoprivileges.console$ sudo whoami
When prompted, enter the user's password. If the command returns
root, it confirms that the user can execute commands with sudo privileges. For advanced configurations, such as managing password prompts or restricting specific commands, refer to this article.
Follow the steps below to create a new user and assign sudo privileges on AlmaLinux, Rocky Linux, or CentOS.
Create a new user. Replace
johnwith your preferred username.console$ sudo adduser john
Set a password for the new user.
console$ sudo passwd john
When prompted, enter and confirm a secure password.
Add the user to the
wheelgroup to grantsudoprivileges.console$ sudo usermod -aG wheel john
Confirm that the
wheelgroup is configured to allowsudoaccess.Open the sudoers file with
visudo:console$ sudo visudo
Ensure the following line is uncommented:
ini%wheel ALL=(ALL:ALL) ALL
This allows all users in the
wheelgroup to run commands withsudo.Switch to the new user account.
console$ sudo su - john
Run a
sudocommand to test privileges.console$ sudo whoami
Enter the user's password when prompted. If the output is
root, the user has successfully been grantedsudoprivileges.
Follow the steps below to create a new user and assign sudo privileges on a FreeBSD system.
Install the
sudopackage.console# pkg update && pkg install sudo
View the installed version of
sudo.console# sudo -V
Create a new user account.
console# adduserWhen prompted, enter the username and other details such as UID, shell and password.
Add the newly created user to the
wheelgroup.console# pw usermod john -G wheel
Open the sudoers file using
visudo.console# visudoMake sure the following line is uncommented to allow users of the
wheelgroup to usesudo.ini%wheel ALL=(ALL:ALL) ALL
Switch to the new user account.
console# su - john
Run a
sudocommand to verify access.console$ sudo whoami
When prompted, enter the user's password. If the output is
root, the user hassudoprivileges.
Conclusion
In this article, you learned how to create a sudo user in Debian-based and FreeBSD systems. You created a new user, assigned the appropriate group membership (sudo or wheel), and verified administrative access using sudo. These steps improved system security by limiting direct root usage and enabled controlled, auditable administrative privileges across different operating systems.