Linux User, Group & Permission Commands

Linux User, Group & Permission Commands

User and permission management is one of the most important aspects of Linux system administration. Whether you are a DevOps engineer, system administrator, or Linux beginner, understanding how users, groups, and file permissions work is essential for maintaining system security and stability.

This is Part 2 of our Linux command series. In this guide, you’ll learn how to create and manage users, work with groups, and control file access using permissions. Each command is explained with clear examples so you can practice confidently.


Linux User, Group, and Permission Commands – Overview

CommandDescription
useraddCreate a new user account
passwdSet or change a user password
idDisplay user UID, GID, and groups
groupaddCreate a new group
usermodModify user accounts
chownChange file owner
chgrpChange group ownership
chmodChange file permissions

 User Management Commands

Create a New User

sudo useradd john
sudo useradd -m -s /bin/bash john

The useradd command creates a new user account. The -m option creates a home directory, and -s defines the default shell.

Set or Change User Password

sudo passwd john

This command assigns or updates a password for a user. Only root or sudo users can change other users’ passwords.

View User Details

id john

Displays the user ID (UID), group ID (GID), and all groups the user belongs to.

Switch Users

su - john

Switches to another user and loads their environment variables.

Run Commands as Root

sudo apt update

The sudo command allows permitted users to run commands with administrative privileges.

Delete a User

sudo userdel john

Removes a user account from the system. Use with caution.


Group Management Commands

Create a Group

sudo groupadd developers

Creates a new group that can be used to manage permissions for multiple users.

View All Groups

getent group

Displays all system groups from the group database.

Add User to a Group

sudo usermod -aG developers john

Adds a user to a supplementary group without removing existing group memberships.

Delete a Group

sudo groupdel developers

Deletes a group from the system if it’s no longer required.


File Ownership Commands

Change File Owner

sudo chown john file.txt

Changes the ownership of a file to the specified user.

Change Group Ownership

sudo chgrp developers file.txt

Assigns a file to a specific group.

Change Owner and Group

sudo chown john:developers file.txt

Updates both the user and group ownership in a single command.

Recursive Ownership Change

sudo chown -R john:developers myfolder

Recursively changes ownership for a directory and all its contents.


File Permission Commands

Full Permissions (Not Recommended)

chmod 777 file.txt

Grants read, write, and execute permissions to everyone. This is insecure and should be avoided in production.

Set Specific Permissions

chmod 751 file.txt

Permission breakdown:

  • Owner: Read, Write, Execute
  • Group: Read, Execute
  • Others: Execute only

Recursive Permission Change

chmod -R 777 myfolder

Applies permissions to all files and subdirectories. Use carefully to avoid security risks.


You’ve now learned how to manage users, groups, ownership, and permissions in Linux. In the next part of this series, we’ll cover process management, networking, and package commands.

Be the first to comment

Leave a Reply

Your email address will not be published.


*