Server Gigabit Guide

Superuser Accounts, sudo & root: A Practical Guide

You are here:
Estimated reading time: 2 min

This guide is designed to provide a comprehensive overview of superuser accounts, sudo, and root in Linux. It is intended for beginners who are new to Linux and want to understand the basics of user management.

The Root User, Regular Users, and System Users

In Linux, there are three main types of users: the root user, system users, and regular users.

  • Root User: The root user is the most powerful user in Linux. It has the ability to perform any action on the system, including creating and deleting users, modifying files, and installing software.

  • System Users: System users are created by the operating system and are used to run background processes. These users cannot be logged in to directly.

  • Regular Users: Regular users are the typical users of a Linux system. They have limited privileges and can only perform actions that are explicitly allowed to them.

Checking if You Are Logged in as a Root

To check if you are logged in as a root, look at the command prompt. The first word before the ‘@’ sign is the name of your user. If it is ‘root’, then you are logged in as a root.
Logged in as

Printing the Current User’s Username

To print the current user’s username, use the following command:

whoami

Central User Database

Linux stores information about all users in a file named ‘/etc/passwd’. The ‘cat’ command can be used to browse this file.
/etc/passwd file

Understanding the ‘/etc/passwd’ File

The ‘/etc/passwd’ file contains a list of users, with each user’s information on a separate line. The format of each line is as follows:

username:x:user_id:group_id:user_info:home_directory:shell

The third column of each line contains the user’s ID. The user ID for root is 0. Values 1 to 500 are reserved for system users. Values starting from 1000 are reserved for regular users.

Becoming a Superuser

To become a superuser, you must log in as root. However, you can also elevate your privileges temporarily using the ‘sudo’ command.

Using sudo

To use sudo, simply type ‘sudo’ before the command that requires superuser privileges. For example, to update the system, you would use the following command:

sudo apt-get update

Gaining Superuser Rights for the Whole Session

To gain superuser rights for the whole session, use the following command:

sudo -i

Tom to elevate the rights to root
This will change your command prompt to reflect that you are now a superuser. To check your current user ID, use the following command:

id

ID for regular users and root

Managing Sudo Permissions

Sudo is denied
Not every user is allowed to use sudo. To give a user permission to use sudo, use the following command:

sudo usermod -aG sudo Cordelia

To remove a user’s permission to use sudo, use the following command:

sudo gpasswd -d Cordelia sudo

Conclusion

This guide has provided an overview of user rights in Linux, with a focus on the root user, regular users, and system users. It has also explained how to become a superuser using sudo and how to manage sudo permissions.

Was this article helpful?
Dislike 0
Views: 6