---
title: "Add Users and Grant Root Privileges in Linux"
source: "https://docs.nexcess.com/hosting/server-administration/linux/adding-users-and-granting-root-privileges/"
description: "This guide walks you through adding a new user on a Linux server, setting their password, and granting `sudo` privileges from the command line."
vertical: "Hosting"
date: "2024-03-04"
last_modified: "2026-07-29"
---

# 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.

Control Panels

  
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**](https://docs.nexcess.com/hosting/control-panel/whm/cpanel/website-management/creating-a-cpanel-user-account/)**,** [**Plesk**](https://docs.nexcess.com/hosting/control-panel/plesk/security/adding-a-user-in-plesk/)**,** and [**InterWorx**](https://docs.nexcess.com/hosting/control-panel/interworx/siteworx/website-management/creating-a-user-account-domain-in-interworx-web-panel/).

## Prerequisites

- A server running a Linux distribution.
- Root or Sudo [SSH access to the server.  ](https://docs.nexcess.com/hosting/server-administration/linux/logging-into-your-server-via-secure-shell-ssh/)
- Basic familiarity with using a terminal.

## Add a New Linux User

1. 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)](https://docs.nexcess.com/hosting/server-administration/linux/logging-into-your-server-via-secure-shell-ssh/).
2. Run the command below, make sure to switch “newuser” with your desired username.

```
`adduser newuser`
```

adduser usage

- 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

1. 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`
```

passwd usage

- 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.

Resetting your own password

Running the passwd command without a username, will change **your own password**.

## Grant Root Privileges via Sudo

Elevated privileges

Root privileges allow a user to make any changes they want to the server. Only grant these privileges when absolutely necessary!

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.

1. 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`
```

2. Once in this file we will need to search for this line below.

```
`## Allow root to run any commands anywhereroot ALL=(ALL) ALL`
```

3. 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`
```

4. To finish adding your user to the file, hit the **Esc** key and then type

```
`:wq`
```

visudo usage

While 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-basedusermod -aG sudo newuser      # Debian/Ubuntu`
```

To confirm a user’s group membership run:

```
`groups newuser`
```

## **Troubleshooting & FAQs**

Why is a new user having problem running sudo commands?Make sure the user was added to the sudoers file correctly. Run visudo and confirm there’s a line like:

```
<strong>newuser ALL=(ALL) ALL</strong>
```

Why am **I getting an “user is not in the sudoers file” error when trying sudo**?This means the user hasn’t been granted sudo privileges. Double-check your visudo changes and save again with :wq.

****Is it safe to log in directly as root instead of using sudo?****It’s best practice to log in as a normal user and elevate privileges with sudo. This improves security and ensures command usage is logged.

How can I regain access after ******editing the sudoers directly and locking myself out?******You must fix the sudoers file by logging in as root via SSH (if available) or booting into single-user/recovery mode to correct the syntax. Always use visudo, since it checks syntax before saving.

---

## **Related Articles and Next Steps**

- [Logging into Your Server via SSH  ](https://docs.nexcess.com/hosting/server-administration/linux/logging-into-your-server-via-secure-shell-ssh/)
- [Understanding File Permissions in Linux  ](https://docs.nexcess.com/hosting/server-administration/linux/file-management/file-permissions/)
- [Security Overview](https://docs.nexcess.com/hosting/security/)
