When you first provision a new Ubuntu server from a cloud provider, you are often given access to the “root” account. The root account is the ultimate administrator—it has absolute power to execute any command, modify any file, and delete the entire operating system without warning.
Using the root account for daily tasks is a massive security risk. A single typo can destroy your server. The established best practice in Linux administration is to create a standard user account and grant it “sudo” (Superuser Do) privileges. This allows the user to run administrative commands only when explicitly requested, providing a crucial safety net.
Step 1: Create the New User Account
Log into your Ubuntu server using your current administrative account (either root or an existing sudo user).
- To create a new user, you will use the
addusercommand. Unlike the olderuseraddcommand,adduseris interactive and automatically sets up the user’s home directory. Type the following, replacingusernamewith the name of the new account (e.g.,johnordeveloper):
sudo adduser username - The system will create the user and immediately prompt you to enter a new password. Type a strong password and press Enter. (Note: For security reasons, Linux will not display any characters or asterisks on the screen while you type).
- Retype the password to confirm it.
- The prompt will then ask for additional information, such as the user’s Full Name, Room Number, and Work Phone. All of this is entirely optional. You can simply press Enter to skip through each of these fields.
- Finally, type Y and press Enter to confirm that the information is correct.
The new standard user account now exists, but they currently do not have permission to install software or edit system configuration files.
Step 2: Grant Sudo Privileges
In Ubuntu, the easiest way to grant a user administrative rights is to add them to the built-in sudo group. Any user belonging to this group can temporarily elevate their privileges by typing sudo before a command.
- To add your new user to the sudo group, use the
usermodcommand:
sudo usermod -aG sudo username
Command Breakdown: The -a flag stands for “append”, ensuring you are adding them to a new group without removing them from their existing groups. The -G flag specifies the group name (sudo).
Step 3: Test the New Sudo User
Before you close your current SSH session and lock yourself out of the server, you must verify that the new user can actually execute administrative commands.
- Switch to the new user account without logging out by using the substitute user (su) command:
su - username - Notice that your terminal prompt has changed from
root@servertousername@server. - Now, attempt to run a command that requires administrative privileges, such as updating the package list:
sudo apt update - The system will ask you for the new user’s password. It will also display the classic Linux security lecture (“With great power comes great responsibility”).
- Enter the password. If the command runs successfully and updates the repositories, the sudo privileges are working correctly.
You can now safely disconnect your root session and use this new account for all future server administration tasks.