The Wayback Machine - https://web.archive.org/web/20241128003950/https://www.geeksforgeeks.org/user-management-in-linux/
Open In App

User Management in Linux

Last Updated : 03 Sep, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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

Awk-Command-to-List-Out-all-the-Users-in-Linux

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  

id-of-any-username

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  

Adding-a-user-in-linux

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  

assigning-a-password-to-the-user-in-linux

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 

Accessing-a-user-configuration-file

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  

Changing-the-user-id-in-linux

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  

modifying-the-group-id-of-a-user-in-linux

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  

Changing-user-login-name-in-linux

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  

changing-home-directory-for-a-user-in-linux

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  

deleting-a-user-in-linux-forcefully

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.

User Management in Linux – FAQs

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.



    Previous Article
    Next Article

    Similar Reads

    Configure Passwordless Sudo For A Specific User in Linux
    Linux has a tough permission rule. Being a root user you are permitted to do anything however the normal user has only some allowed permissions. To run many other commands, they required to ask permissions from the superuser, using keyword sudo after which they need to enter the password. This requirement of the password after sudo command can be r
    1 min read
    Anonymity and Privacy For Linux User
    Today, more than 3 billion of the world's population is connected to the virtual world known as the internet in some way or another. And the size of the hard-wares and data centers is on the increase every year due to insufficient users' information holding capacity. The lack of awareness and knowledge behind the proper functioning of the internet
    6 min read
    Deleting a User in Linux using Python Script
    Deleting a user from your system or server via a python script is a very easy task. You just need to pass the username of the user and the script will remove the details and all the files of that user.This python script uses userdel Linux command to delete the user.You can directly use userdel command if you remember the command but if you don't th
    2 min read
    Creating a User With an Expiry Date in Linux
    Linux is a multi-user system and thus, it allows more than one person to interact with the system at the same time. There are numerous ways in which we can create new users in Linux. The system administrator has the responsibility to manage different users of the system. For types of users in Linux refer Users in Linux System Administration. User a
    2 min read
    How to Block or Disable Normal User Logins in Linux?
    Here we will see how to block or disable normal user logins in Linux. This is a good idea to prevent Normal users from connecting to your system. We will see how to block Normal user logins using /etc/nologin file. We are going to tell the users that what is actually happening by showing them a message. The main function of /etc/nologin file is to
    2 min read
    Scylla – Phone Number & User Information Gathering Tool in Kali Linux
    Scylla is a free and open-source tool available on Github. Scylla is based upon the concept of Open Source Intelligence (OSINT). This tool is used for information gathering. Scylla is written in python language. You must have python language installed in your Kali Linux in order to use the Scylla tool. Scylla is an advanced tool that allows it's us
    4 min read
    How to Force User to Change Password at Next Login in Linux
    For security reasons, you must frequently change the password of accounts on the system. In this article, we are going to see how we can force the user to change the password on the next login in Linux. We can do that by two methods, one is using `passwd` command and the other is by using the `chage` command. Using passwd commandTo force a user to
    3 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)Valgrind (memwatch)GDB1. 'print' Statement The 'print' s
    3 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 this objective, each with its different advantages
    3 min read
    How to list all locked user accounts in linux?
    Linux is great for managing administration tasks, which include managing access, authorizations, and file permissions in a system. While managing user accounts and groups you might encounter some accounts which need to be blocked or locked in order to ensure safety. But once you lock an account how can you see which all accounts are locked or banne
    4 min read
    How to Grant Admin Privileges to a User in Linux
    Linux is an operating system that is open source operating system. There are many distros available in Linux distribution like Ubuntu, Kali Linux, Arch Linux, and Red Hat Linux. In this article, we will understand how to give admin privileges to non-admin users in the Ubuntu Operating system. Introduction to Permissions, Users, and GroupsLinux is a
    5 min read
    What is umask and how to set umask of Apache user in linux
    In the Linux environment, the user mask or umask plays the most important role in specifying default permission for newly created files and directories. Umast filters or subtracts permission bits from the default permissions, ensuring it is a more secure and controlled environment. In Apache, configuring the umask is important for managing the secu
    4 min read
    How to Change The Primary Group of a User in Linux?
    In the field of Linux system administration, learning the modification of the primary group is essential. In this article, we are going to deliver concise details about user groups and how to manage them. What is a Primary Group?In Linux, every user is associated with a primary group. The primary group is a fundamental concept in Unix-like operatin
    7 min read
    How to Add User to a Group in Linux
    A group in Linux is a way to put users with similar access and permissions in a collection. By using groups, an administrator can define access control and permissions for all the users belonging to that group. Without groups, the administrator would have to define roles for individual users however, with groups those roles can be given to a group
    7 min read
    How to Check the Groups a User Belongs to in Linux?
    This article shows how to check the groups a user belongs to in Linux operating systems. We introduce some concepts related to the topic and then describe how to do so using the groups command available on the terminal. Groups in LinuxAll Linux operating systems are designed as multi-user operating systems. This means that they provide the capabili
    8 min read
    Manually Add a User Without Tools Like useradd and adduser in Linux
    Adding a user manually in Linux without using tools like useradd or adduser involves modifying system files directly. This method is not recommended for regular use, as it requires careful editing of system files and can lead to errors if not done correctly. However, in some situations, such as when these tools are not available or not working, it
    9 min read
    How to restrict a user's login to certain times of the day or week in linux?
    In this article, we explore the significance of time-based user login restrictions in Linux as an important security measure. By leveraging Pluggable Authentication Modules (PAM) and time configuration files, administrators can define specific periods when users are allowed or denied access. This detailed article outlines the step-by-step process,
    4 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 using most of the disks hence causing a DOS. Thir
    7 min read
    Introduction to Graphical User Interface of RedHat Linux Operating System
    Red Hat Linux-based operating system from Red Hat designed for business. It's one of the highly used Enterprise Operating System in the Linux market. It's an open-source Operating System. Feasible to work on desktops, on servers, or on the cloud.  Red Hat and Its community-supported counterpart. Fedora, are among the most widely used Linux distribu
    3 min read
    How to add User in Linux | useradd Command
    useradd is a command in Linux that is used to add user accounts to your system. It is just a symbolic link to adduser command in Linux and the difference between both of them is that useradd is a native binary compiled with the system whereas adduser is a Perl script that uses useradd binary in the background. It makes changes to the following file
    5 min read
    How to Change User Password in Linux | passwd Command
    Securing user accounts is a fundamental aspect of maintaining a robust and secure Linux system. One essential task is changing user passwords regularly to prevent unauthorized access. The passwd command in Linux provides a straightforward and effective way to modify user passwords. This article will guide you through the process of changing user pa
    8 min read
    How to create a Shared Folder between two Local User in Linux?
    This article shows how to set-up a shared folder between two local users in Linux. The shared directory/folder will be accessible to both the users, they will be able to read/write each other's file. Let us create shared directory /home/shareFolder for user Bob and Alice and add them to a common group named projectA. Note: You can create the uses B
    2 min read
    How to unlock a locked user account in linux?
    To regulate access and maintain security, Linux/Unix systems must have the ability to lock and unlock user accounts. It offers the adaptability required to handle a range of security and operational scenarios while ensuring that only authorized users have access. In this article, we’ll explore why this functionality is important and cover some of t
    7 min read
    How to Delete User in Linux | userdel Command
    Managing user accounts is an essential aspect of Linux system administration. Understanding how to delete a user in Linux is crucial, whether you need to remove an unused account, revoke access for a departing employee, or clean up your system for security reasons. Here, we will explore the 'userdel' command, a powerful tool in Linux for removing u
    6 min read
    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 type in Linux. it includes files like - text file
    4 min read
    What is init.d in Linux Service Management?
    In Linux there are several services that can be started and stopped manually in the system, some of their services are ssh, HTTP, tor, apache, etc. To start and run these services we used to simply type service "service name" start/stop/status/restart Example: service ssh start And to check if this service is running we type the command service ssh
    2 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 the group and becomes the first and only member of
    4 min read
    Process Management in Linux
    A process means program in execution. It generally takes an input, processes it and gives us the appropriate output. Check Introduction to Process Management for more details about a process. There are basically 2 types of processes. Foreground processes: Such kind of processes are also known as interactive processes. These are the processes which
    3 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: It is the common file type in Linux. it includes f
    4 min read
    YUM Commands for Linux Package Management
    If you are a Linux user or system administrator, chances are you've come across YUM (Yellowdog Updater, Modified) at some point in your journey. YUM is a powerful package management tool that simplifies the process of installing, updating, and managing software on Red Hat-based Linux distributions like CentOS and Fedora. In this article, we will de
    4 min read
    Article Tags :
    three90RightbarBannerImg