How to Create a New User with Full Root Privileges in Linux


1 views

The adduser --system command creates a system account without root privileges by default. If you need to grant full administrative access to a new user, you'll need to explicitly configure sudo permissions.

Here's the complete process for creating a user with root-equivalent access:

sudo adduser newadmin
sudo usermod -aG sudo newadmin

After creating the user, verify they can execute commands with root privileges:

su - newadmin
sudo whoami
# Should output "root"

For direct root access without sudo (not recommended for security reasons):

sudo adduser --uid 0 --gid 0 newroot
# OR modify existing user:
sudo usermod -u 0 -g 0 existinguser

When granting root privileges:

  • Always use strong passwords
  • Consider using SSH keys instead of passwords
  • Limit root access to specific commands when possible

To customize sudo access through the /etc/sudoers file:

sudo visudo
# Add this line for full access:
newadmin ALL=(ALL:ALL) ALL
# Or for specific commands only:
newadmin ALL=(ALL:ALL) /usr/bin/apt,/usr/bin/systemctl

When you need to create a new user with root-level access in Linux, the adduser command alone won't suffice. The --system flag actually creates a system account without a password and with restricted privileges, which is the opposite of what we want.

Here's the proper way to create a new user with root privileges:

sudo adduser newadmin
sudo usermod -aG sudo newadmin

For different use cases, consider these approaches:

# Method 1: Adding to sudoers file directly
echo "newadmin ALL=(ALL:ALL) ALL" | sudo tee -a /etc/sudoers

# Method 2: Using visudo (safer)
sudo visudo
# Then add: newadmin ALL=(ALL) NOPASSWD: ALL

After setup, verify the new user's privileges:

sudo -U newadmin -l

Granting root access should be done carefully:

  • Only give root access to trusted users
  • Consider using NOPASSWD only in specific cases
  • Regularly audit your sudoers file

If the new user still can't execute sudo commands:

# Check group membership:
groups newadmin

# Verify sudoers configuration:
sudo cat /etc/sudoers | grep newadmin