Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Linux User Administration: Overview
2.1.
Types of User Accounts
2.2.
Groups
3.
Working with Linux User Administration
3.1.
Listing Out All the Users in Linux
3.2.
Getting the ID of any Username
3.3.
Adding a User
3.4.
Assigning Password to User
3.5.
Accessing a User Configuration file
3.6.
Changing the User Login name
3.7.
Changing User ID for a User
3.8.
Changing the Home Directory
3.9.
Deleting a Username
3.10.
Adding a Group
3.11.
Modifying the Group ID of a User
3.12.
Deleting a Group
4.
Frequently Asked Questions
4.1.
What categories of Linux users are there?
4.2.
What should a Linux administrator know?
4.3.
What three sorts of user accounts are there?
4.4.
How many different kinds of Linux user groups exist?
4.5.
What is the root user in Linux?
5.
Conclusion
Last Updated: Mar 27, 2024
Medium

Linux User Administration

Master Python: Predicting weather forecasts
Speaker
Ashwin Goyal
Product Manager @

Introduction

Hello Techies!

We hope you have a basic idea of the Linux Operating System and its advantages. Now it’s time to explore Linux in more detail. In this blog, we will be discussing Linux User Administration.

Introduction

So let’s get into the topic!

Linux User Administration: Overview

In an operating system, managing various user accounts and their associated rights is known as user administration.

Types of User Accounts

Super User: The root account is another name for this user. It has full permissions and is unrestrictedly able to execute every command. To run a command as the root user, the keyword ‘sudo’ is frequently used. For example, database administrators, network engineers, and application developers.

Normal User: This account is given to the system's regular users. Access to the system's commands and files is restricted for this account. Such an account can be created, its rights changed, or the root user can delete it. For example, human users that are created by root.

System User: This type of account is designed only for a particular program, software, or function, for example, a mail account.

We can establish various user accounts, classify them into different categories, modify their permission settings, or even delete them on Linux- or Unix-based operating systems. The following section goes over the terminal commands for each of the abovementioned steps.

Id finding out

Groups

We can create groups of user accounts in operating systems based on Linux or Unix to handle user accounts together. We have control over the group's access rights. A single user may belong to several groups, while a group may contain several users.

There are mostly four types of user administrators: Network Administrators, Database Administrators, Server/Web Administrators, and Security Systems Administrators.

Now let’s see how to implement Linux User Administration and the essential commands.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Working with Linux User Administration

In this blog section, we will learn about the vital commands in Linux User Administration and an implementation example.

Listing Out All the Users in Linux

We can use the “awk command” with the -F option to list all the Linux users. Here, we're using print $1 and awk to retrieve a file and print just the first column.

awk -F':' '{ print $1}' /etc/passwd
Listing all users

Getting the ID of any Username

We can use the “id command” to get the ID of any username. Each user has an ID allocated to them, which is used to identify each user. This ID doubles as the user group ID by default.

id username
Id

Adding a User

A new user is added to the directory with the useradd command. Depending on the category it belongs to, the ID is automatically assigned to the user. The user's username will be what we specified in the command.

sudo useradd username

Adding users

Assigning Password to User

We can assign a password to a user using the passwd command. Following the usage of this command, the user's password must be updated with the new password by entering it.

passwd username

Assigning Password to User

Accessing a User Configuration file

Following is the command that prints the data of the configuration file. This file contains information about the user in a specific format which can be noticed in the image provided below.

cat /etc/passwd

Accessing a User Configuration file

Changing the User Login name

Using the “usermod command,” you can modify the user's login name. Change the user's login name with the command listed below. The user's old login name gets replaced with the new one that you have chosen.

sudo usermod -l new_login_name old_login_name

Changing the User Login name

Changing User ID for a User

This command enables changing a user's user ID. The command will assign the new ID and remove the old ID for the user with the specified username.

usermod  -u newlyassigned_id username

Changing User ID for a User

Changing the Home Directory

The command below modifies the username-specified user's home directory and sets the user's new home directory to the directory specified by the command's path.

usermod -d new_home_directory_path username

Changing the Home Directory

Deleting a Username

The command listed below deletes the user whose username is given. Verify that the user is not a member of any groups. If the user is a group member, it cannot be erased immediately; instead, we must first take him out of the group before we can delete him.

userdel -r username

Deleting a Username

Adding a Group

The snippet below demonstrates how to create a new group using the groupadd command.

sudo groupdadd group_name

Adding a Group

Modifying the Group ID of a User

This command enables changing a user's group ID, which enables adding a user to an existing group. It will modify the user's group ID and set the user's group ID to the provided new group id.

usermod -g  new_group_id username

Modifying the Group ID of a User

Deleting a Group

To delete a group, we can use the “groupdel command”.

groupdel group_name

Deleting a Group

If we try to delete the same group again, we will find that it does not exist anymore. The image below shows it clearly.

Showing that group is deleted

Frequently Asked Questions

What categories of Linux users are there?

In Linux, there are three different user types: root, regular, and service.

What should a Linux administrator know?

A Linux system administrator must understand firewalls, databases, working networks, and network security. The reason is that although your primary role is that of a Linux system administrator, you also belong to a broader support team and frequently need to collaborate to resolve challenging issues.

What three sorts of user accounts are there?

Standard Accounts for users are used for regular computing. The most powerful accounts, known as administrator accounts, should only be utilized when necessary. Those who only require temporary access to a computer should use guest accounts.

How many different kinds of Linux user groups exist?

The Linux operating system divides groups into two categories: primary groups and secondary groups.

What is the root user in Linux?

The ‘root account’ is a special user in the /etc/passwd file with a user ID (UID) of 0 and is commonly given the user name root. The UID value of 0 makes the root account so special, not the user name. This also means that any user with a UID of 0 has the same privileges as the root user.

Conclusion

This blog discussed Linux User Administration in detail. We discussed users, groups, and crucial Linux user administration concepts. Then we proceeded to learn and implement the commands for Linux User Administration. We hope that this article has provided you with the help to enhance your knowledge regarding Linux User Administration, and if you want to learn more, do check out our Linux-related articles on:

If you found this blog has helped you enhance your knowledge, and if you want to learn articles like Linux Environment, check out our articles below:

 

Please refer to our guided paths on Coding Ninjas Studio to learn more about DSA, Competitive Programming, JavaScript, System Design, etc. And also, enroll in our courses and refer to the mock test and problems available. Have a look at the interview experiences and interview bundle for placement preparations.

Keep learning, and Keep Growing!

Happy Learning!

Previous article
Linux File System
Next article
Linux Users and Permissions
Live masterclass