By default, Ubuntu locks the root user account for security reasons, preventing direct root logins. Instead, administrative tasks are performed using the sudo
command, which grants temporary root privileges to regular users. This guide will walk you through creating a new user and granting them sudo privileges on Ubuntu 20.04 LTS.
Creating a User with Sudo Privileges
Step 1: Create a new user account using the adduser
command. Replace <username>
with your desired username. You'll be prompted to set a password and, optionally, provide additional user information.
sudo adduser <username>
Since only users with administrative privileges can add new users, the sudo
command is required here. This means your current user must already have sudo access to execute this command.
Step 2: Add the new user to the sudo
group to grant sudo privileges. Members of this group can execute commands with root privileges by prefacing them with sudo
.
sudo adduser <username> sudo
The user is now part of the sudo group and has administrative privileges.
Testing the Sudo User
Step 3: Switch to the new user account to verify the sudo privileges. Use the su
command followed by a hyphen and the username.
su - <username>
After switching, you'll notice the command prompt reflects the new username. Additionally, a welcome message may appear, indicating that the user can use sudo
for administrative tasks.
Step 4: Confirm the sudo access by performing a command that requires root privileges. For example, create a directory named tmp
in the /etc
directory.
sudo mkdir /etc/tmp
You'll be prompted to enter the new user's password. If the command executes successfully, it confirms that the user has sudo privileges. You can verify the creation of the directory by listing the contents of /etc
:
ls /etc
By completing these steps, you've successfully created a new user with sudo privileges on your Ubuntu 20.04 LTS system. If you ever need to revoke sudo access from this user, you can remove them from the sudo group using the deluser
command:
sudo deluser <username> sudo
Member discussion