Search Our Database
How to create a user with Root privilege in Linux
Introduction
This guide provides step-by-step instructions on how to create a user with root privileges in a Linux environment. This is a security-conscious practice that allows you to avoid using the root account for day-to-day activities, thus reducing the chances of accidental system changes or potential security risks. By the end of this guide, you will be able to create a user that can execute administrative commands using sudo.
Prerequisites
- Root access to the server via SSH.
- Basic knowledge of SSH commands and Linux system administration.
Step-by-Step Guide
Step 1: Access the Server via SSH
Login to your Server as root user:
ssh root@[your_server_ip]
Step 2: Create a New User
Use the following command to create a new user, replacing newuser with your chosen username:
useradd newuser passwd newuser
Step 3: Grant Root Privileges to the New User
- To provide the new user with root (sudo) privileges, you can add to the sudo or wheel group, depending on your Linux distribution.
- For Debian-based distributions (e.g., Ubuntu):
usermod -aG sudo newuser
- For Red Hat-based distributions (e.g., CentOS, RockyLinux, AlmaLinux):
usermod -aG wheel newuser
Step 4: Verify sudo access
- Switch to the new user to verify that the sudo privileges are properly assigned:
su - newuser
- Once logged in as the new user, test the sudo access by running a command that requires elevated privileges, such list a directory on root directory
sudo ls /root
- The system will prompt you to enter the password for newuser to confirm the privileges.
Conclusions
Creating a user with root privileges enhances system security by preventing direct root access. It is an effective method for managing administrative tasks while keeping your server secure. Always remember to test the new user after setup