Linux Tutorial
Linux File/Directory Management
Linux Packaging And Compression
Vim Text Editor
Linux Text Processing
Linux Software Installation
Linux User/User Group Management
Linux Permission Management
Linux Filesystem Management
Linux Advanced Filesystem Management
Linux System Management
Linux Backup and Recovery
Linux System Service Management
Linux System Log Management
Linux Boot Management
LAMP/LNMP Environment
SELinux Management
In Linux, users and user groups are essential concepts for managing system access and resources. Users represent individual accounts with unique login credentials, while groups allow multiple users to share access to files, directories, and other system resources. This tutorial will cover an overview of users, user groups, and their management in Linux.
Linux users
A user in Linux is an individual account with a unique identifier (UID) that allows someone to log in and access system resources. Each user has a username, password, and additional information such as their full name, home directory, and default shell.
There are two main types of users in Linux:
Regular users: These users have limited access to system resources and typically can't perform administrative tasks without elevated privileges.
Superusers (root user): The root user, or superuser, has unrestricted access to the entire system and can perform any action without limitations. The root user should be used with caution, as mistakes can lead to serious system damage.
Linux user groups
User groups in Linux are collections of users that can be used to manage access to files, directories, and other system resources. Each group has a unique group identifier (GID) and a name. Users can belong to one primary group and multiple secondary groups.
Groups are especially useful for managing permissions on shared resources, as you can grant or restrict access to a group instead of managing each user individually.
Managing users
There are several commands for managing users in Linux:
useradd
: Creates a new user account.usermod
: Modifies an existing user account.userdel
: Deletes an existing user account.passwd
: Sets or changes a user's password.Managing groups
Commands for managing groups in Linux include:
groupadd
: Creates a new group.groupmod
: Modifies an existing group.groupdel
: Deletes an existing group.gpasswd
: Sets or changes a group's password.Viewing user and group information
To view information about users and groups in a Linux system, you can use the following files:
/etc/passwd
: Contains user account information, such as usernames, UIDs, default shells, and home directories./etc/shadow
: Holds encrypted user passwords./etc/group
: Contains group information, including group names and GIDs./etc/gshadow
: Holds encrypted group passwords.You can use tools like cat
, grep
, and less
to view or search for information in these files.
Changing user and group ownership
To change the owner or group of a file or directory, you can use the chown
and chgrp
commands:
chown
: Changes the owner of a file or directory.chgrp
: Changes the group of a file or directory.Managing file permissions
File permissions in Linux are controlled using a combination of owner, group, and other user permissions. The chmod
command allows you to change file permissions for the owner, group, and others.
In conclusion, users and user groups in Linux are essential for managing access to system resources. By creating and managing users and groups, you can maintain a secure and organized environment for your system's resources. Understanding the various commands for managing users, groups, and file permissions will help you effectively administer a Linux system.
How to create a user in Linux:
useradd
command to create a new user in Linux.# Example: Creating a new user sudo useradd username
Managing user passwords in Linux:
passwd
command to manage user passwords, set or change passwords.# Example: Setting/changing a user password sudo passwd username
Viewing user details and attributes in Linux:
id
or finger
command to view user details and attributes.# Example: Viewing user details id username
Creating and managing user groups in Linux:
groupadd
command to create a new group in Linux.# Example: Creating a new group sudo groupadd groupname
Adding users to groups and group permissions:
usermod
command to add users to groups, and manage group permissions with chmod
.# Example: Adding a user to a group sudo usermod -aG groupname username
Changing user passwords and policies:
passwd
command to change user passwords, and manage password policies in /etc/security/pwquality.conf
.# Example: Changing a user password sudo passwd username
Troubleshooting user and group-related issues in Linux:
# Example: Troubleshooting user/group issues sudo journalctl | grep username