Linux Users and Groups

User and group management in Linux is fundamental to security and access control in the multi-user environment.

← Back to Linux Basics

User and group management in Linux is fundamental to security and access control in the multi-user environment. It involves managing accounts, organizing users into groups, and assigning permissions to control access to files and resources. 

Key Concepts

Users: Each user has a unique username and a User ID (UID). The root user is the superuser with administrative privileges.
Groups: Groups are collections of users that simplify permission management. Each user belongs to a primary group (often their own name by default) and can belong to multiple secondary (supplementary) groups. Groups have a unique Group ID (GID).
Permissions: Access rights (read, write, execute) are assigned to three categories: the file owner, the file's group, and others (everyone else).
Configuration Files: Key information is stored in plain text files:
/etc/passwd: Stores user account information (except passwords).
/etc/shadow: Stores encrypted user passwords.
/etc/group: Stores group information and members.
/etc/sudoers: Defines which users or groups have sudo (superuser) privileges. 

Administrative Commands (User, Group & Permissions)

Administrative tasks typically require sudo or root privileges. These commands are essential for managing users, groups, and permissions in Linux.

Category Command Purpose Example Man
User Management useradd Creates a new user account. Use -m to create the home directory. sudo useradd -m devuser man
User Management passwd Sets or changes a user’s password. sudo passwd devuser man
User Management usermod Modifies user properties such as groups or home directory. sudo usermod -aG sudo devuser man
User Management userdel Deletes a user account. Use -r to remove home directory. sudo userdel -r devuser man
Group Management groupadd Creates a new group. sudo groupadd devops man
Group Management usermod -aG Adds a user to a supplementary group. sudo usermod -aG devops devuser man
Group Management groupmod Modifies group properties such as name or GID. sudo groupmod -n devops-team devops man
Group Management groupdel Deletes a group. sudo groupdel devops man
Group Management gpasswd -d Removes a user from a specific group. sudo gpasswd -d devuser devops man
Permissions & Ownership ls -l Lists file details including permissions and ownership. ls -l /var/www man
Permissions & Ownership chown Changes file or directory owner and group. sudo chown user:group file man
Permissions & Ownership chmod Changes file or directory permissions. chmod 755 script.sh man
Permissions & Ownership id / groups Displays user UID, GID, and group memberships. id devuser man

Best Practices