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
File Management in Linux
In Linux, most of the operations are performed on files. And to handle these files 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. Linux has 3 types of files: Regular Files: It is the common file
4 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
Types of User Profile Management in LINUX
User profile management is an essential topic in the profile management system, and it describes how the user can handle the profile. Various types of user-profiles management in Linux are - bashrcbash_profilebash_historybash_logoutbashrc Procedures Open the terminal and add the user.useradd t1Switc
1 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
Some time-saving tips for Linux Users
Are you making most out of the Linux? There are lots of helpful features which appears to be time saving Tips and Tricks for many of Linux Users. Sometimes these time saving Tips and Tricks become the need. They help you to get productive with the same set of commands yet with enhanced functionality
4 min read
Linux Process Management Command Cheat Sheet
On Linux computers there are special commands to control the programs that are running. These commands are called process management commands. With the help of process management commands you can look at the list of the programs that are currently running on your computer. You can also start new pro
6 min read
User Space Debugging Tools in Linux
In this article, we will discuss debugging tools in Linux. Debugging Tools are those programs that allow us to monitor, control, and correct other program's error while they execute. Some of the debugging tools are as follows:- 'print Statement'Querying (/proc, /sys etc)Tracing (strace/ltrace)Valgri
3 min read
How to use User Quotas in Linux
The control of user quotas in Linux is a very effective facility that provides system administrators with the ability to limit disks usage of particular users or groups of users in order to protect against disk overloading. When quotas are set, it will be easier to stop any user or even a group from
7 min read
Nano Text Editor in Linux
In the vast world of Linux text editors, Nano stands out as a simple yet powerful tool for editing files directly from the command line interface. Whether you're a novice user or an experienced developer, Nano offers a straightforward and efficient editing experience. In this article, we'll delve in
8 min read