List of content you will read in this article:
What is sudo?
There will be various commands you can only use with root privileges.
Anytime you enter commands that require root privileges, which are the commands that generally make changes to the system, you will need access to root or sudo.
Sudo is a program that you can use in place of root. Therefore, it grants some permissions to local users to run commands with brute privileges.
One of the benefits of using sudo is that it allows you to forego the root account completely.
Once you have sudo set up, you can lock the root account. Because technically, you should not need it anymore.
You should not have root enabled for SSH login because you want to avoid the problems that may cause.
Everything is considered a file in Linux; what does it mean?
There is a concept that everything is a file in Linux. The correct statement is that everything is a file descriptor or a process.
This doesn't sound very clear since the Linux system includes other entities such as directories, symbolic link processes, pipes, and sockets.
The point is that everything has a common set of tools, APIs, or system-level commands.
Therefore, every access can be done using the same set of operations versus something like Windows, where you have different reads for sockets, files, and pipes with different options and use cases.
This is an oversimplification, which gives us a high-level overview of the Linux architecture.
It suggests that every single entity is considered a file on a Linux system, and a unique descriptor or identifier represents each. So, this is where they get the concept that everything is a file.
How can file permissions help users on Ubuntu Linux?
The above description leads us to the concept of file permissions and directories. Each file has its permissions and directories in Linux and its distros, such as Ubuntu.
These permissions control the users’ access rights and privileges. So, as a user, if a file or a directory belongs to you, you can have access to it, or edit, rename, and even delete it.
What are the risks of logging in as the root user on the Ubuntu Linux system?
Not all users are the same on the Ubuntu Linux system. Some of them, such as the unique user of the root, have an administrative job with the highest privileges.
The problem is these users are not bound to any permission restrictions and can do anything it needs to, from accessing the system files, modifying them, installing and uninstalling programs, or customizing the system.
As you can see, the root user can be very dangerous while they can disrupt the system whether they intend to do so or not! On many regular occasions, they will be in the OR NOT position!
This is why we do not recommend you log in to the system as the root user. Instead, you can always run the system commands as a sudo user.
What is a sudo user?
According to what we said, a sudo user is a regular Ubuntu Linux user with higher privileges. This lets them run commands as a root user or any other regular one.
Remember, the sudo program may be configured to restrict a sudo user in a way to have limited access to commands, or it can let them run all commands as the root user.
To avoid any problem, we recommend you, as a system administrator, give limited permissions to the sudo user to perform just the required actions.
What is the sudoers group?
Sudo or sudoers group is basically like an admin group, which gives you root access.
How to create a sudo user?
Here, we will talk about how to create or add a user to the sudo or sudoers group, and we will modify a little bit of the general permissions and restrictions around sudo. Let’s go and first get started with the way you can add a user to this group step by step:
- Login to your Ubuntu Linux server as the root user using this syntax:
$ ssh root@server-ip
- Type the root password and press ENTER on your keyboard.
- When logged in to the remote server, create a new sudo user using this command:
$ sudo adduser username
- This command not only helps you to create a new sudo user but also makes a primary group with the same name and adds the newly created user to it.
- Now, you need to set a new strong password for the new user.
- Please re-enter the password to confirm it.
- You should answer the set of questions about the new user. It is recommended to accept the default values.
- Type Y and press ENTER.
How to add the new sudo user to the sudoers group?
You can add the new user to the sudoers group following these steps:
- Press Ctrl + Alt + T and log in to your terminal.
- Type and enter the following command:
# sudo usermod -aG sudo groupname
- Remember, the members of a sudoers group have sudo permissions on Ubuntu by default.
How to check the sudo access and permissions for new users?
You can log in as the new user to test and check the sudo access by the following command:
# su - username
- You should also check whether you can use the sudo command with the new user. In this regard, you must put the word sudo at the beginning of the command that needs root permission to be executed:
# sudo command_to_run
- Now, you are logged in as a new user.
- Check the permissions using the following command:
# sudo ls -la /root
- Enter the password and be sure that the whole process is working.
The Bottom Line
Managing users’ permissions and restrictions and providing them specific privileges according to their requirements on Ubuntu is one of the most important tasks of the root user. Here, you learned about creating sudo users and the way to add them to the sudoers group. Remember, you should only grant these privileges to highly trusted users. Good luck!
By purchasing a buy linux vps, you can have full control over your hosting environment and tailor it to your specific needs, allowing you to optimize performance and ensure reliable uptime for your applications or website.
People also read: