Tutorial Setup Sudo Privileges For User In Ubuntu 20.10 Server. Due to standard definitions, sudo is a program for the Unix-like computer operating system that allows users to run programs with the security privileges of another user. Buy a Linux VPS to have a real experience with this guide.
Tutorial Setup Sudo Privileges For User In Ubuntu 20.10 Server
As an administrator, you need to run your applications in Linux. You can choose two ways to do this. First, is to switch to the superuser which is also called root and the su command will be used if you use this solution. The second way is to take advantage of sudo. due to what distribution you use, you should decide which way is more suitable. For example, if you are using Fedora, Red Hat, or openSuSE, they enable the root user but others like Ubuntu and Debian do not. However, sudo is important to many Linux distributions as it allows a user to run a program as another user. Sometimes it not depend on what distribution you are currently using, there will come a time when you will have to take advantage of sudo.
How do I Setup Sudo Privileges For User In Ubuntu 20.10 Server
What Is The Difference Between sudo And su
If you are used to working with a traditional Linux setup, you may use su command to gain root privileges to log in as the root. But it is recommended to not log in as the root user. Every time you use a distribution that relies on su and allows the root user login, login as your standard user, and su to the root user. But with sudo-based distributions, you can not log in as a root user. In some distributions like Ubuntu, the root user account is “disabled” and you see that standard user accounts are restricted from performing sensitive tasks, such as viewing the contents of the /root directory. So, you can not log in as root and you can not su to become the root user. So, users need the help of sudo to gain administrative privileges to do this issue. Additionally, you will use sudo command as the preferred means to handle elevated permissions. Using the sudo commands will grant elevated permissions for 15 minutes in Ubuntu.
%admin ALL=(ALL) ALL
sudo usermod -a -G sudo USERNAME
Note 2: Obviously, USERNAME is the name of the user to be added. After all, once the user logs out and logs back in, they will now enjoy full sudo privileges.
Creating A New Sudo-enabled User On Ubuntu 20.10
Let’s go through the steps (If you want to configure sudo for an existing user, skip to step 3) of this guide to learn how to create a new user with sudo access on Ubuntu 20.04 without having to modify your server’s /etc/sudoers file.
Step1: SSH into your server as the root user to log into your Server:
ssh [email protected]_server_ip_address
Step2: Use the adduser command to add a new user to your system:
Note3: You should replace noodi with the username that you want to create. You will be prompted to create and verify a password for the user. Also, you will need to fill in some information about the new user. It is fine to accept the defaults and leave this information blank.
Step3: It is time to type the usermode command and add the user to the sudo group:
usermod -aG sudo sammy
Step4: At the final step, you should test that if the new sudo permissions are working are nor. You can use the su command to switch to the new user account:
su - sammy
Now that you created a new user, also verify that you can use sudo by prepending sudo to the command that you want to run with superuser privileges:
From now on, you can list the contents of the /root directory which is normally only accessible to the root user:
sudo ls -la /root
Note4: You will be prompted for the password of that user’s account if this is the first time you are using sudo in a session.
How To Delete Sudo Users
any time is needed, you can remove sudo permissions from a user. But you are able to do this without having to delete him/her completely. Be careful when you are removing a sudo user in Ubuntu systems and watch to not remove the real administrator from the “sudo” group. Consider that there should be at least one sudo user in the system.
Type the command below to revoke sudo permissions from a user:
sudo deluser ubuntuserver sudo
Note5: You may see your user name instead of “ubuntuserver” and consider that this command will only remove your preferred user from the sudo group, but it will not delete the user permanently from the system.
Also, you can run the following command to revoke the sudo permission from the user. In this way, the user becomes a regular user and can’t do any administrative tasks with sudo permission.
sudo gpasswd -d ubuntuserver sudo
sudo -l -U ubuntuserver
How To Delete Users Permanently In Ubuntu 20.10 Server
As you reviewed till now, you have only removed the users from the “sudo” group. But what should be done about the user still exists in the system? If you need to remove a user completely from a Linux system, log in as root or sudo user and run
sudo deluser <username>
Also, you can remove a user along with their home directory and mail spool. Run the following command to do this:
sudo deluser --remove-home ubuntuserver
In this article, you learned How To set up Sudo Privileges For User In Ubuntu 20.10 Server. After all, 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. Also, you can read more on Initial server setup on Ubuntu 20.04.