When managing a server, you’ll sometimes want to allow users to execute commands as “root,” the administrator-level user. The
sudo command provides system administrators with a way to grant administrator privileges — ordinarily only available to the root user — to normal users.
In this tutorial, you’ll learn how to create a new user with
sudo access on Ubuntu 20.04 without having to modify your server’s
Note: If you want to configure
sudo for an existing user, skip to step 3.
Step 1 — Logging Into Your Server
SSH in to your server as the root user:
- ssh [email protected]your_server_ip_address
Step 2 — Adding a New User to the System
adduser command to add a new user to your system:
- adduser sammy
Be sure to replace
sammy with the username that you want to create. You will be prompted to create and verify a password for the user:
OutputEnter new UNIX password: Retype new UNIX password: passwd: password updated successfully
Next, you’ll be asked to fill in some information about the new user. It is fine to accept the defaults and leave this information blank:
OutputChanging the user information for sammy Enter the new value, or press ENTER for the default Full Name : Room Number : Work Phone : Home Phone : Other : Is the information correct? [Y/n]
Step 3 — Adding the User to the sudo Group
usermod command to add the user to the sudo group:
- usermod -aG sudo sammy
Again, be sure to replace
sammy with the username you just added. By default on Ubuntu, all members of the sudo group have full
Step 4 — Testing
To test that the new
sudo permissions are working, first use the
su command to switch to the new user account:
- su - sammy
As the new user, verify that you can use
sudo by prepending
sudo to the command that you want to run with superuser privileges:
- sudo command_to_run
For example, you can list the contents of the
/root directory, which is normally only accessible to the root user:
- sudo ls -la /root
The first time you use
sudo in a session, you will be prompted for the password of that user’s account. Enter the password to proceed:
Output:[sudo] password for sammy:
Note: This is not asking for the root password! Enter the password of the sudo-enabled user you just created.
If your user is in the proper group and you entered the password correctly, the command that you issued with
sudo will run with root privileges.
In this quickstart tutorial, we created a new user account and added it to the sudo group to enable
For your new user to be granted external access, please follow our section on Enabling External Access for Your Regular User.
We checked one ubuntu server in this tutorial. You can have a set of tools to achieve your development targets. One of the most interesting stacks is the LAMP stack. Our blog post on [[2020-04-04-how-to-install-wordpress-with-lamp-on-ubuntu-1604.md|install lamp ubuntu 16.04]] explains how to install WordPress with LAMP on Ubuntu 16.04.
You might want also to secure your installation with SSL. Our blog post on [[2020-07-05-how-to-create-a-selfsigned-ssl-certificate-for-apache-on-centos-8.md|generate ssl certificate apache]] explains why how to create a self-signed SSL certificate for Apache on CentOS 8.
If you need more detailed information on setting up an Ubuntu 20.04 server, please read our Initial Server Setup with Ubuntu 20.04 tutorial.