Adding & Editing users and groups in a Linux System

Sonam Kumari Singh
4 min readNov 21, 2023

--

Linuxis a Multi-user system, which means more than one user can work in the same system at the same time. We must have to create an account in order to work with Linux as we cannot keep working with the root account. We have one administrative account, a system administrator account is responsible for managing the user accounts and groups of the system.

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.

On Linux, everything starts at “root.” The hard drive has a root partition ( / ), and the default initial user is root (often referred to as the “superuser”).

user

User must authenticate to any system they need to us, 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.

User account information is stored in the /etc/passwd file. This information includes the account name, password, home directory location, and default shell, among other values.

Create, Delete and Modify user account

user account can be managed using command line tool. Here are the basic command on rhel.

Note: These commands require root or administrative privileges, so use the “sudo” before each command.

  1. useradd/passwdused to add / create new user and set password

>> sudo useradd “user_name”

>> sudo passwd “created_user_name”

Settings for the useradd command are stored in the /etc/defaults/useradd file.

2. usermod — used to edit / modify user like login username, id

>> sudo usermod -l “new_login_name” “old_login_name”

>> sudo usermod -u “new_id” user_name

Standard options for usermod include:

--comment (-c): Modifies the comment field

--home (-d): Modifies home directory information

--expiredate (-d): Changes account-expiration settings

--login (-l): Modifies the username

--lock (-L): Locks a user account

--unlock (-U): Unlocks a user account

3. userdel — used to delete user account

>> sudo userdel -r “user_name”

>> userdel “user_name” # It will not delete home directory

group

In Linux, group are collection of user’s. The main motive of creating a group is to define the set of permissions such as read and write permission or allowing the shared resources of groups.

Group information is stores in the /etc/group file and is the default configuration file.

Creating, Modify and Delete group

group account can be managed using command line tool. Here are the basic command on rhel.

groupaddadd group

>> sudo groupadd “group_name” # When a group is created, a unique group ID gets assigned to that group.

>> sudo groupadd -g 1009 “group_name # If you want to create a group with a specific group ID (GID), use the --gid or -g option

groupmod — modify a group

# You can rename a group using groupmod with the --new-name or -n option

>> sudo groupmod -n “new_group_name” “old_group_name”

groupdeldelete a group

>> groupdel “group_name”

Add and remove users from a group

Adding secondary group to user’s, Use the usermod command with the --append --groups options (-a and -G for short):

>> sudo usermod -aG “group_name” “user_name”

Look in the /etc/group file or use the id command to confirm your changesTo remove user from a group

>> id “user_name”

To remove a specific user from a group, you can use the gpasswd command with — -delete / -d to modify group information

>> sudo gpasswd -d “user_name” “group_name”

add and remove command

💕Thank You !! 💕

--

--

Sonam Kumari Singh

SONAM here! Grateful for your connection! Tech enthusiast exploring new languages, deep into DevOps, with a spotlight on Linux. 😊🚀