Table of Contents
Why File Permissions and Ownership Matter in Linux
Linux Permission Basics: Read, Write, Execute
Permission Categories: User, Group, Others
Understanding the Permission String
File Ownership: User and Group
Changing Permissions with chmod
Changing Ownership with chown and chgrp
Special Permission Bits
Viewing Detailed File Information
Best Practices for Managing Permissions
Advanced Tip: Access Control Lists (ACLs)
Conclusion
Home System Tutorial LINUX Mastering Linux File Permissions and Ownership

Mastering Linux File Permissions and Ownership

May 10, 2025 am 09:02 AM

Mastering Linux File Permissions and Ownership

In the world of Linux, where multi-user systems and server security are foundational principles, understanding file permissions and ownership is crucial. Whether you're a beginner exploring your first Linux distribution or a seasoned system administrator managing critical servers, knowing how permissions work is key to ensuring the integrity, privacy, and functionality of your system.

This guide will take you deep into the core of Linux file permissions and ownership—what they are, how they work, how to modify them, and why they matter.

Why File Permissions and Ownership Matter in Linux

Linux is built from the ground up as a multi-user operating system. This means:

  • Multiple users can operate on the same system simultaneously.

  • Different users have different levels of access and control.

Without a permissions system, there would be no way to protect files from unauthorized access, modification, or deletion. File permissions and ownership form the first layer of defense against accidental or malicious activity.

Linux Permission Basics: Read, Write, Execute

Each file and directory in Linux has three basic types of permissions:

  • Read (r) – Permission to view the contents of a file or list the contents of a directory.

  • Write (w) – Permission to modify a file or create, rename, or delete files within a directory.

  • Execute (x) – For files, allows execution as a program or script. For directories, allows entering the directory (cd).

Permission Categories: User, Group, Others

Permissions are assigned to three distinct sets of users:

  • User (u) – The file's owner.

  • Group (g) – A group associated with the file.

  • Others (o) – Everyone else.

So for every file or directory, Linux evaluates nine permission bits, forming three sets of rwx, like so:

rwxr-xr--

This breakdown means:

  • rwx for the owner

  • r-x for the group

  • r-- for others

Understanding the Permission String

When you list files with ls -l, you’ll see something like this:

-rwxr-xr-- 1 alice developers 4096 Apr 4 14:00 script.sh

Let’s dissect it:

  • - – Regular file (other values include d for directory, l for symbolic link, etc.)

  • rwx – Owner (alice) has read, write, and execute permissions

  • r-x – Group (developers) has read and execute permissions

  • r-- – Others can only read the file

  • 1 – Number of hard links

  • alice – Owner

  • developers – Group

  • 4096 – File size in bytes

  • Apr 4 14:00 – Last modification date

  • script.sh – File name

File Ownership: User and Group

Every file and directory in Linux is associated with:

  • An owner (a user)

  • A group

When a user creates a file:

  • They become the owner by default.

  • The file is assigned to the user's primary group.

You can view ownership details using:

ls -l filename

To check group membership:

groups username

Changing Permissions with chmod

To change permissions, Linux uses the chmod command in two modes:

Symbolic Mode

This mode uses letters and symbols:

  • u = user (owner)

  • g = group

  • o = others

  • a = all

Operators:

  • = add permission

  • - = remove permission

  • = = assign exact permission

Examples:

chmod u x script.sh # Add execute to owner chmod g-w file.txt # Remove write from group chmod o=r file.txt # Set read-only for others

Numeric Mode

This mode uses octal values to represent permission bits:

Permission Value
Read (r) 4
Write (w) 2
Execute (x) 1

You sum these for each category:

  • 7 = rwx

  • 6 = rw-

  • 5 = r-x

  • 4 = r--

Example:

chmod 755 script.sh

Means:

  • Owner: 7 = rwx

  • Group: 5 = r-x

  • Others: 5 = r-x

Changing Ownership with chown and chgrp

To change the owner and group of a file:

chown newuser:newgroup filename

Change only the owner:

chown newuser filename

Change only the group:

chgrp newgroup filename

Example:

chown alice:staff report.txt

Sets alice as the owner and staff as the group.

Special Permission Bits

In addition to the standard rwx permissions, Linux includes three special permission bits:

Setuid (Set User ID)
  • Applies to executable files

  • Runs the program with the permissions of the file owner, not the user who runs it

chmod u s filename

Example permission string: -rwsr-xr-x

Setgid (Set Group ID)
  • On files: similar to Setuid, but uses group permissions.

  • On directories: new files inherit the group of the directory.

chmod g s dirname

Sticky Bit
  • Applies to directories

  • Only the file owner can delete files within the directory, even if others have write access.

Common on shared directories like /tmp.

chmod t /shared

Permission string: drwxrwxrwt

Viewing Detailed File Information

Two common ways to view permissions and ownership:

ls -l

ls -l filename

Shows basic file type, permissions, owner, group, and size.

stat

stat filename

Displays:

  • File type

  • Access rights

  • Owner and group

  • Inode and link count

  • Timestamps

Example output:

File: script.sh Size: 2048 Blocks: 8 IO Block: 4096 regular file Device: 802h/2050d Inode: 131072 Links: 1 Access: 2025-04-04 14:00:00.000000000 0000 Modify: 2025-04-04 13:45:00.000000000 0000 Change: 2025-04-04 13:50:00.000000000 0000 Birth: -

Best Practices for Managing Permissions

  • Use the principle of least privilege – grant only the necessary permissions.

  • Avoid using chmod 777 unless absolutely necessary—it makes files writable and executable by everyone.

  • Use groups to manage shared access to directories or files.

  • Regularly audit permissions using tools like find or acl.

Example to find world-writable files:

find / -type f -perm -o w

Advanced Tip: Access Control Lists (ACLs)

Standard permissions are sometimes not enough. ACLs allow more fine-grained access control.

Enable and view ACLs with:

getfacl filename setfacl -m u:bob:rw filename

This gives user bob read/write access to filename even if he’s not the owner or in the group.

Conclusion

Linux file permissions and ownership are not just a dry technical concept—they’re the foundation of system security and multi-user cooperation. Whether you're setting up a simple script or managing a production server, understanding and applying these concepts correctly ensures safety, control, and peace of mind.

Take the time to practice:

  • Create files and change their permissions

  • Test ownership with different users

  • Use tools like ls, chmod, chown, and stat

Once you master these tools, you'll unlock a much deeper level of control over your Linux system.

The above is the detailed content of Mastering Linux File Permissions and Ownership. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1671
14
PHP Tutorial
1276
29
C# Tutorial
1256
24
Does the internet run on Linux? Does the internet run on Linux? Apr 14, 2025 am 12:03 AM

The Internet does not rely on a single operating system, but Linux plays an important role in it. Linux is widely used in servers and network devices and is popular for its stability, security and scalability.

What is the salary of Linux administrator? What is the salary of Linux administrator? Apr 17, 2025 am 12:24 AM

The average annual salary of Linux administrators is $75,000 to $95,000 in the United States and €40,000 to €60,000 in Europe. To increase salary, you can: 1. Continuously learn new technologies, such as cloud computing and container technology; 2. Accumulate project experience and establish Portfolio; 3. Establish a professional network and expand your network.

What are the main tasks of a Linux system administrator? What are the main tasks of a Linux system administrator? Apr 19, 2025 am 12:23 AM

The main tasks of Linux system administrators include system monitoring and performance tuning, user management, software package management, security management and backup, troubleshooting and resolution, performance optimization and best practices. 1. Use top, htop and other tools to monitor system performance and tune it. 2. Manage user accounts and permissions through useradd commands and other commands. 3. Use apt and yum to manage software packages to ensure system updates and security. 4. Configure a firewall, monitor logs, and perform data backup to ensure system security. 5. Troubleshoot and resolve through log analysis and tool use. 6. Optimize kernel parameters and application configuration, and follow best practices to improve system performance and stability.

What are the differences in virtualization support between Linux and Windows? What are the differences in virtualization support between Linux and Windows? Apr 22, 2025 pm 06:09 PM

The main differences between Linux and Windows in virtualization support are: 1) Linux provides KVM and Xen, with outstanding performance and flexibility, suitable for high customization environments; 2) Windows supports virtualization through Hyper-V, with a friendly interface, and is closely integrated with the Microsoft ecosystem, suitable for enterprises that rely on Microsoft software.

What is the main purpose of Linux? What is the main purpose of Linux? Apr 16, 2025 am 12:19 AM

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

Is it hard to learn Linux? Is it hard to learn Linux? Apr 18, 2025 am 12:23 AM

Learning Linux is not difficult. 1.Linux is an open source operating system based on Unix and is widely used in servers, embedded systems and personal computers. 2. Understanding file system and permission management is the key. The file system is hierarchical, and permissions include reading, writing and execution. 3. Package management systems such as apt and dnf make software management convenient. 4. Process management is implemented through ps and top commands. 5. Start learning from basic commands such as mkdir, cd, touch and nano, and then try advanced usage such as shell scripts and text processing. 6. Common errors such as permission problems can be solved through sudo and chmod. 7. Performance optimization suggestions include using htop to monitor resources, cleaning unnecessary files, and using sy

The Future of Linux Software: Will Flatpak and Snap Replace Native Desktop Apps? The Future of Linux Software: Will Flatpak and Snap Replace Native Desktop Apps? Apr 25, 2025 am 09:10 AM

For years, Linux software distribution relied on native formats like DEB and RPM, deeply ingrained in each distribution's ecosystem. However, Flatpak and Snap have emerged, promising a universal approach to application packaging. This article exami

Top 7 Tools to Compare Files in Linux (with Examples) Top 7 Tools to Compare Files in Linux (with Examples) Apr 28, 2025 am 09:21 AM

This guide explores various methods for comparing text files in Linux, a crucial task for system administrators and developers. We'll cover command-line tools and visual diff tools, highlighting their strengths and appropriate use cases. Let's assum

See all articles