Manage Users And Groups

In Linux, user management involves creating, modifying, and deleting user accounts. User accounts are used to authenticate and authorize users to access resources on the system.

Here are some key concepts related to user management in Linux:

Root user: The root user is the superuser with complete control over the system. The root user can create, modify, and delete other user accounts.

User ID (UID): Each user account has a unique user ID. The root user has a UID of 0, while other users have UIDs greater than 0.

Group ID (GID): Each user account is associated with one or more groups, which have a unique group ID. A group can contain multiple users, and users can belong to multiple groups.

Passwords: User accounts can be password-protected to prevent unauthorized access. Passwords are stored in encrypted form in the /etc/shadow file.

Home directory: Each user account has a home directory where their personal files and settings are stored.

Some common commands used for user management in Linux include:

sudo: Sudo is a command in Linux and other Unix-based operating systems that allows users to perform actions with administrative or “root” privileges without logging in as the root user. The name “sudo” stands for “superuser do” or “substitute user do”.

The sudo command provides a way for authorized users to run specific commands as root or another user with elevated privileges. This helps to prevent accidental or malicious damage to the system by limiting the scope of what a user can do with administrative privileges.

useradd: Used to create a new user account. Create the user:

sudo useradd username

Set the password

sudo passwd username

Create a home directory for the new user using the mkdir command:

sudo mkdir /home/username

userdel: Used to delete a user account

sudo userdel username

usermod: Used to modify a user account (e.g., change the password, group membership, or home directory).add the new user to one or more groups using the usermod command. For example, to add the user to the “sudo” group (which grants administrative privileges), use:

sudo usermod -aG sudo username

passwd: Used to change a user’s password

sudo password username

groupadd: Used to create a new group

sudo groupadd groupname

getent: verify the group exists

getent group groupname

groupdel: Used to delete a group

sudo groupdel groupname

groups: Used to display groups that a current or specific user belongs too

groups username

chown: Used to change the ownership of a file or directory

sudo chown username filename

You can also change the ownership of a directory and its contents using the -R (recursive) option:

sudo chown -R username directoryname

chgrp: Used to change the group ownership of a file or directory

sudo chgrp groupname filename

Change the group ownership of a directory and its contents using the -R (recursive) option:

sudo chgrp -R groupname directoryname

Leave a Reply

Your email address will not be published. Required fields are marked *