When installing Ubuntu, or any Linux distro, a root user will be created. However, there are many times when you need to create additional users with root or sudo privileges. Thankfully, Linux makes this fairly simple to do using the adduser and usermod commands for creating new users and adding them to specific group assignments.
Let’s take a look new users to Linux machines and granting them sudo permissions!
Create a User in Linux using the adduser Command
The adduser command is used to create a new user in Linux. The simplest usage of this command is to call it by passing in the username of the new user you would like to create. Calling this command must be done as root, you can do this with the help of sudo.
sudo adduser <username>
Tip: You can run the shell as
rootby using thesudo -scommand. This will run the shell with elevated root privileges until you type theexitcommand. This can help if you are running multiple commands that will need root privileges so you don’t need to prefix every command withsudo.
When calling the adduser command, you will be prompted for additional information for the user account you are creating. The required thing to enter will be the Password for the user, but it will also prompt for additional user metadata that is optional.

adduser command to create a new user on LinuxGive Linux User Root / Sudo Permissions
Now that we have a new user created on our Linux machine, this user will also need to be assigned root permissions so they are made an administrator on this machine. This can be done by on Ubuntu by adding the user to the sudo group. With default configuration of Ubuntu, being a member of the sudo group will grant the user sudo privileges.
The usermod command can be used to assign the desired user to the sudo group within Ubuntu Linux. Keep in mind this command must be run with sudo privileges, so you’ll need to use sudo to run it.
sudo usermod -aG sudo <username>
Notice the -aG flag is used with the usermodcommand. This flag will append this user to the specified group. Then the command must be given the <username> of the User you will be modifying. In this case we are specifying the sudo group to append the specified user to.

sudo groupCheck if Logged in User has sudo Privileges
Once a user have been added to the sudo group on Ubuntu they will have sudo privileges. If you are logged into an Ubuntu machine and don’t know if you have sudo privileges, then you can use the sudo command with the -l flag to check.
sudo -l
This command will list out all sudo privileges you have. If you do not have any, then it will return a message that reads “Sorry, user <username> may not run sudo on <machine-name>.”

sudo privileges on LinuxLookup All Users in sudo Group
In Linux, the /etc/group file is used to determine the groups that users belong to. The contents of this file will list out all group assignments on a particular Linux machine. You can look within this file to check if a given user is a member of a group; like checking if the user is in the sudo group.
An easy way to check if a user is in the sudo group, is to lookup what users are members of the sudo group as listed within the /etc/group file using the cat command to output to the console, and the grep command to search within the file before outputing to the console. You can do this with the following command:
sudo cat /etc/group | grep sudo

sudo groupAnother related query to this, is to use grep to search for the users name instead of sudo. This would enable you to lookup all the groups the specified user is a member of using this same command.
cat /etc/group | grep chris

Wrap Up
Once this command is run successfully, the specified user will now be a part of the sudo group on your Ubuntu machine. They will now essentially be an administrator with root permissions on the machine. Use the adduser and usermod commands, you can create new admin accounts for additional users and grant them sudo privileges on your Ubuntu Linux machines. Additionally, checking the /etc/group file will enable you to lookup what groups different users are already assigned to.
Original Article Source: Add New Root User to Ubuntu Linux Server using Bash written by Chris Pietschmann (If you're reading this somewhere other than Build5Nines.com, it was republished without permission.)
Stop Wasting Hours Writing Unit Tests: Use GitHub Copilot to Explode Code Coverage Fast
Microsoft Azure Regions: Interactive Map of Global Datacenters
Create Azure Architecture Diagrams with Microsoft Visio
Byte Conversion Calculator from KB, MB, GB, TB, PB
Azure CLI: List and Set Azure Subscription






great article! all i need is here! thanx!