sudo is a program for Unix-like computer operating systems that allows a user to run programs with the security privileges of another user (superuser by default). When administering a server, you may want users to be able to run commands as root, an administrator-level user. The sudo command allows a system administrator to grant regular users administrative privileges normally available only to the root user. In this tutorial will show you how to create a sudo user with sudo user on Ubuntu 20.04 without changing the server’s /etc/sudoers file.
Requirements
- 99RDP VPS/Dedicated Server(Running Ubuntu 20.04)
- Access To Terminal
Connecting To The Ubuntu Server
Firstly, SSH into your Ubuntu server by using the given command.
# ssh root@server_ip_address
Creating A Sudo User On Ubuntu 20.04
Next we are going to use the adduser command to add user deadpool to the system.
# adduser deadpool
Please Don’t forget to replace deadpool with the username that you want to create. After running the command you will be prompted to create and verify a password for the user:
Following you will be asked to fill in the details for new user. You can edit it or choose to go with the default by pressing enter key.
Now as the user is created we are going to add the user to the sudo group by running the given command.
# usermod -aG sudo deadpool
Please replace deadpool with the username you just added. By default Ubuntu members of the sudo group have full sudo privileges.
Verifying The sudo Access
Lastly we are going to verify the sudo access. Following this we are going to use the su command to switch to the newly created user.
# su deadpool
As the new user, make sure you can use sudo by prepending sudo to commands that you want to run with superuser privileges.
# sudo ls /etc
The first time you use a sudo command you will be asked for the users password. Enter the password to proceed. If the user is in the sudo group and you entered the password correctly, the command that you issued with sudo will run with root privileges and will list you the contents of dir etc.
Deleteing A Sudo User
Finally to delete a sudo-enabled user simply run the given command in terminal to delete the user and its home directory in Ubuntu 20.04.
# userdel -r deadpool
Don’t forget to replace the username with your system username that you created.
Conclusion
Now you know how to create a sudo user on Ubuntu 20.04. Before sudo, users used the su command to log into a system with full system-wide privileges. This was dangerous as it could be exploited by tricking users into entering malicious commands. These vulnerabilities were addressed by restricting account permissions. However, administrators had to log out of their accounts and log back into their administrator accounts to perform normal tasks. Ubuntu’s sudo command strikes a balance between allowing privileged users to perform administrative tasks while protecting user accounts from malicious or accidental corruption.