Search Our Database
How to Add a New User in Linux Using the Command Line
Introduction
Managing users is a fundamental task in Linux system administration. Adding a user allows administrators to assign appropriate permissions, segregate workloads, and secure system access across different team members or applications. This is particularly important in shared environments, servers hosted on cloud platforms, or when setting up automation tasks that require distinct user privileges.
The useradd and adduser commands are commonly used to create new users in Linux. Both commands achieve similar outcomes but vary slightly depending on the Linux distribution. For example, adduser is more interactive and commonly found in Debian-based systems, while useradd is standard on Red Hat-based distributions and is more script-friendly. Understanding the differences and learning how to use these commands effectively is key to managing users on any Linux system.
Adding a user includes several steps: defining the username, optionally setting a password, assigning home directories, setting default shells, and configuring user groups. In many server deployments, users are also assigned to specific groups to control access to directories, services, or administrative tools. Additionally, users may require sudo privileges if they need to execute administrative commands.
This article is intended for system administrators and Linux users who need to add new user accounts via the command line on a Linux server or desktop. It covers both useradd and adduser, explains the key options, and provides a practical example of creating users with and without administrative privileges.
Prerequisites
- A Linux-based system (Debian, Ubuntu, CentOS, RHEL, AlmaLinux, etc.)
- Access to a terminal
- Root access or a user account with sudo privileges
- Basic familiarity with Linux command-line operations
Step-by-step Guide
Step 1: Check Current Users (Optional)
Before adding a new user, it may be helpful to list existing users:
cut -d: -f1 /etc/passwd
Step 2: Add a New User
Use the adduser or useradd command depending on your distribution:
For Debian/Ubuntu systems:
sudo adduser newusername
This will prompt for a password and other optional details such as full name and phone number.
For CentOS/RHEL/AlmaLinux:
sudo useradd -m newusername
Set a password:
sudo passwd newusername
Step 3: Add User to a Group (Optional)
To add the user to a specific group (e.g., sudo for admin rights):
Debian/Ubuntu:
sudo usermod -aG sudo newusername
CentOS/RHEL:
sudo usermod -aG wheel newusername
Step 4: Verify the New User
To confirm the user was created successfully:
id newusername
You should see the user’s UID, primary group, and any additional groups assigned.
Step 5: Switch to the New User (Optional)
To switch to the new user account:
su - newusername
Conclusion
Adding users in Linux is an essential skill for managing access, improving security, and organizing system resources. This guide demonstrated how to create new users with or without a home directory, assign passwords, and optionally grant administrative privileges by adding users to the appropriate group. These steps ensure a structured, secure, and manageable Linux environment.
For advanced user management tasks, consider setting password expiry policies or managing users via LDAP in enterprise environments.
Should you have any inquiries about the guidelines, please feel free to open a ticket through your portal account or contact us at support@ipserverone.com. We’ll be happy to assist you further.