In Linux, managing user accounts and their permissions is crucial for maintaining system security and organization. Sometimes, you may need to create a new user and grant them root privileges to perform administrative tasks. This guide walks you through the steps to create a new user with root (sudo) access in Linux.
Step 1: Create a New User
To add a new user, use the following command:
sudo adduser newusername
Replace newusername with the actual username you want to create. You will be prompted to set a password and enter optional details like full name and contact information.
Step 2: Grant Sudo Privileges
Once the user is created, you need to grant them root privileges by adding them to the sudo group.
sudo usermod -aG sudo newusername
For CentOS, RHEL, and Fedora, use:
sudo usermod -aG wheel newusername
(The wheel group in these distributions has sudo privileges.)
Step 3: Verify the New User’s Access
Switch to the newly created user:
su - newusername
Then, check if the user has sudo privileges:
sudo whoami
If the output is root, the user has been granted sudo access successfully.
Step 4: (Optional) Enable Passwordless Sudo
If you want the user to run sudo commands without being prompted for a password, edit the sudoers file:
sudo visudo
Find the following line:
%sudo ALL=(ALL:ALL) ALL
Modify it to:
%sudo ALL=(ALL:ALL) NOPASSWD:ALL
Save and exit the file.
Conclusion
By following these steps, you can create a new Linux user with root privileges, ensuring that they can execute administrative tasks securely. Always be cautious while granting root access to users, as it allows them to make system-wide changes.
If you have any questions or need further assistance, drop them in the comments below!