A user is an entity, in a Linux operating system, that can manipulate files and perform several other operations. Each user is assigned an ID that is unique for each user in the operating system. In this post, we will learn about users and commands which are used to get information about the users. After installation of the operating system, the ID 0 is assigned to the root user and the IDs 1 to 999 (both inclusive) are assigned to the system users and hence the ids for local user begins from 1000 onwards.Â
In a single directory, we can create 60,000 users. Now we will discuss the important commands to manage users in Linux.Â
1. To list out all the users in Linux, use the awk command with -F option. Here, we are accessing a file and printing only first column with the help of print $1 and awk.Â
awk -F':' '{ print $1}' /etc/passwd

2. Using id command, you can get the ID of any username. Every user has an id assigned to it and the user is identified with the help of this id. By default, this id is also the group id of the user. Â
id username
Example: id test Â

3. The command to add a user. useradd command adds a new user to the directory. The user is given the ID automatically depending on which category it falls in. The username of the user will be as provided by us in the command.Â
sudo useradd username
Example: sudo useradd geeks Â

4. Using passwd command to assign a password to a user. After using this command we have to enter the new password for the user and then the password gets updated to the new password. Â
passwd username
Example: passwd geeks Â

5. Accessing a user configuration file. Â
cat /etc/passwd
This commands prints the data of the configuration file. This file contains information about the user in the format. Â
username : x : user id : user group id : : /home/username : /bin/bash

Now we will go through the commands to modify information.Â
6. The command to change the user ID for a user. Â
usermod -u new_id username
This command can change the user ID of a user. The user with the given username will be assigned with the new ID given in the command and the old ID will be removed.Â
Example: sudo usermod -u 1982 test Â

7. Command to Modify the group ID of a user. Â
usermod -g new_group_id username
This command can change the group ID of a user and hence it can even be used to move a user to an already existing group. It will change the group ID of the user whose username is given and sets the group ID as the given new_group_id.Â
Example: sudo usermod -g 1005 test Â

8. You can change the user login name using usermod command. The below command is used to change the login name of the user. The old login name of the user is changed to the new login name provided. Â
sudo usermod -l new_login_name old_login_name
Example: sudo usermod -c John_Wick John_Doe Â

9. The command to change the home directory. The below command change the home directory of the user whose username is given and sets the new home directory as the directory whose path is provided. Â
usermod -d new_home_directory_path username
Example: usermod -d new_home_directory test Â

10. You can also delete a user name. The below command deletes the user whose username is provided. Make sure that the user is not part of a group. If the user is part of a group then it will not be deleted directly, hence we will have to first remove him from the group and then we can delete him. Â
sudo userdel -r username
Example: sudo userdel -r new_geeks Â

Conclusion
In this article, we explored the concept of users in the Linux operating system, including their unique identification and the range of commands available to manage them. We discussed how user IDs are allocated, beginning with the root user and extending to system and local users. Additionally, we covered important commands that allow you to list, create, modify, and delete users, as well as manage user IDs, group IDs, and home directories. By mastering these commands, you can effectively manage user accounts on a Linux system, ensuring proper configuration and security.
What is the purpose of the useradd
command in Linux?
The useradd
command is used to create a new user account in Linux. It assigns a unique user ID automatically, depending on the user category, and creates a corresponding home directory for the user.
What happens if I delete a user who is part of a group?
If you attempt to delete a user who is part of a group, the deletion may not proceed directly. You should first remove the user from the group using appropriate group management commands, and then delete the user account using the userdel
command.
Similar Reads
User Management in Linux
A user is an entity, in a Linux operating system, that can manipulate files and perform several other operations. Each user is assigned an ID that is unique for each user in the operating system. In this post, we will learn about users and commands which are used to get information about the users.
5 min read
Group Management in Linux
There are 2 categories of groups in the Linux operating system i.e. Primary and Secondary groups. The Primary Group is a group that is automatically generated while creating a user with a unique user ID simultaneously a group with an ID the same as the user ID is created and the user gets added to t
4 min read
Kali Linux - File Management
In Kali Linux, most of the operations are performed on files. And to handle these files Kali Linux has directories also known as folders which are maintained in a tree-like structure. Though, these directories are also a type of file themselves. Kali Linux has 3 basic types of files: Regular Files:
4 min read
7 Linux Commands For Managing Users
Linux is a fantastic platform that allows multi-user access options. Different users can access the same Linux OS for working simultaneously. A user account allows multiple people to access directories, terminals, the Internet, etc. There are three types of user accounts: User Account: This account
3 min read
Making your own Linux Shell in C
To know more about what a shell is, click here. We all use the built in terminal window in Linux distributions like Ubuntu, Fedora, etc. But how do they actually work? In this article, We are going to handle some under the hood features and algorithms what actually work inside a shell. All Linux ope
7 min read
How to Remove Users from Groups in Linux?
Groups in Linux are an important part of organizing the system's access control. Creating separate groups for separate types of roles of users allows the administrator to manage the access control of the Linux system efficiently. It is an essential skill to understand how to add, remove, and update
4 min read
Processes in Linux/Unix
A program/command when executed, a special instance is provided by the system to the process. This instance consists of all the services/resources that may be utilized by the process under execution. Whenever a command is issued in Unix/Linux, it creates/starts a new process. For example, pwd when i
6 min read
How to use Linux Cockpit to manage system performance
Cockpit is a web-based graphical management tool for Linux machines on your computer. Having Cockpit on your server allows you to manage events on the user interface of a browser. Our typical admin tasks include setting up your firewall, changing your network settings, managing storage, creating acc
5 min read
10 Best File Managers For Linux
File Managers are something that is required to manage your daily activities quickly. Using file managers, you can copy, move, rename, and delete files, manage space, manage disks, etc. As a user, we all look for an easy and simple file manager to handle these tasks without having any trouble. Mostl
14 min read
Get Username by User ID in Linux
The need to get user names by User ID is frequently encountered by system administrators in the Linux world. This task is necessary to manage permissions, diagnose, or simply identify users of the Linux system for different management purposes. Fortunately, Linux provides several methods to achieve
3 min read