Add Users and Grant Root Privileges in Linux
Introduction
Adding users allows multiple people to log in and work on the server while letting you control their permissions and track changes.
If your server uses a control panel such as cPanel, Plesk, or InterWorx, the best practice is to create users through the panel rather than the command line. This ensures that all required settings, permissions, and directories are configured automatically. For step-by-step instructions, see our guides for cPanel, Plesk, and InterWorx.
Prerequisites
- A server running a Linux distribution.
- Root or Sudo SSH access to the server.
- Basic familiarity with using a terminal.
Add a New Linux User
- Log into your server as root using your terminal program of choice. If you haven’t logged into your server via SSH before, see Logging into Your Server via Secure Shell (SSH).
- Run the command below, make sure to switch “newuser” with your desired username.
adduser newuser- Run as root or with sudo to create users.
- Use descriptive and unique usernames (e.g., jdoe, dbadmin).
- Keep usernames lowercase with no spaces.
- To check if a user already exists, run the command: id username
- By default, a home directory is created for the new user (e.g., /home/newuser).
- To set a custom home directory, specify that with the –home flag: adduser –home /custom/path newuser
- To set a specific shell, use the –shell flag: adduser –shell /bin/zsh newuser
- On some distros, useradd is the alternative low-level command
Update User Password
- Run the command below to update the password for the newly created user. When setting a new password, the system will not show what you are typing, this is expected.
passwd newuser- Run as root or with sudo to set another user’s password.
- Command format: passwd username (e.g., passwd newuser).
- Password input is hidden (nothing appears while typing).
- Enforce strong passwords — many systems check for length & complexity.
- Use passwd -l username to lock an account.
- Use passwd -u username to unlock an account.
Grant Root Privileges via Sudo
Allowing a user to have root privileges means that the user can do anything they want in the server. It is recommended to limit those that have root privileges. We highly recommend giving users access only to the folders and files they need for their work. This is a great security practice, as it helps prevent them from accidentally deleting or changing critical system files.
- Grant users the ability to run elevated “root” level commands via sudo by editing the sudo users file. Begin by using the command below.
visudo- Once in this file we will need to search for this line below.
## Allow root to run any commands anywhere
root ALL=(ALL) ALL- Add your new user to this list by typing the letter “i” to insert text. Be sure to add this line below “root ALL=(ALL) ALL”, replacing ‘newuser’ with the username of who you want to have sudo privileges.
newuser ALL=(ALL) ALL- To finish adding your user to the file, hit the Esc key and then type
:wqWhile you can safely edit the sudoers file, check for syntax errors before saving.
Instead of listing users individually, you can add them to the wheel group (on RHEL/CentOS/AlmaLinux) or the sudo group (on Debian/Ubuntu):
usermod -aG wheel newuser # RHEL-based
usermod -aG sudo newuser # Debian/UbuntuTo confirm a user’s group membership run:
groups newuser