Operations 12 min read

Master Linux File and User Management: ls, chmod, Groups, and Users Explained

This guide explains how to use Linux commands such as ls -l to interpret file listings, chmod to modify permissions, and various superuser, group, and user management tools, providing syntax, options, examples, and best practices for system administration.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master Linux File and User Management: ls, chmod, Groups, and Users Explained

1. ls -l command

The ls -l command lists files and directories with detailed information. Example output:

-rw-r--r-- 1 user group   4096 Feb 21 10:30 file.txt

Explanation of fields:

File type and permissions : the first character indicates type ( - regular file, d directory, l symlink); the next nine characters are permission bits for owner, group, and others.

Link count : number of hard links to the inode.

Owner and group : user and group names.

File size : size in bytes.

Modification time : timestamp of the last modification.

File name : the name of the file.

By default ls -l shows the current directory; provide a path to list another directory.

2. chmod command

The chmod command changes file or directory permissions. Syntax: chmod [options] mode filename Common options: -R: apply changes recursively. -v: verbose output.

Permission modes can be symbolic or numeric:

Symbolic mode : uses letters u, g, o, a with +, -, =. Example: chmod u+x file.txt adds execute permission for the owner.

Numeric mode : three octal digits representing owner, group, others (r=4, w=2, x=1). Example: chmod 755 file.txt sets rwxr-xr-x.

Example to give read/write to the owner and remove all permissions for group and others:

chmod u+rw,go-rx example.txt

3. Superuser (root)

The superuser has unrestricted access to the system, able to create, modify, delete files, manage users, install software, and more. Switch to the superuser with su or sudo. Use with caution to avoid accidental damage.

4. Group management

Commands to manage groups: groupadd – create a new group. Syntax: groupadd [options] groupname. Example: groupadd mygroup. groupdel – delete an existing group. Syntax: groupdel groupname. Example: groupdel mygroup. groupmod – modify a group's attributes. Syntax: groupmod [options] groupname. Example: groupmod -g 1001 mygroup. groups – list groups a user belongs to. Syntax: groups [username]. Example: groups username. gpasswd – add or remove users from a group. Example to remove: gpasswd -d username mygroup. getent group – query group information from the system database.

5. User management

Key commands: useradd – create a new user. Syntax: useradd [options] username. Example: useradd -m -g myuser (creates a home directory and sets the primary group). userdel – delete a user. Syntax: userdel username. usermod – modify user attributes. Example: usermod -c "My User" myuser. passwd – set or change a user's password. Syntax: passwd [username]. id – display UID and GID of a user. Example: id myuser. cat /etc/passwd – view all user accounts.

6. Viewing user information

Commands to query user data: id – show UID/GID for a specific user. cat /etc/passwd or less /etc/passwd – list all accounts. getent passwd – retrieve user entries from the name service. whoami – display the current login name. groups – list groups for a user.

7. Switching users

Methods to change the active user: su [username] – switch to another user; without a name, switches to root. sudo command – run a command with superuser privileges.

Login shell: su - [username] – start a login session for the target user.

All switching commands require the target user's password (or sudo privileges).

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxUser Managementgroup-managementPermissions
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.