


No longer be afraid of the chmod command, let Linux permission management no longer become your nightmare!
If you are a Linux system administrator or developer, then you will definitely encounter file permission problems. In Linux, file permissions can be set and modified through the chmod command, but the use of this command is quite complicated, which brings a lot of trouble to many beginners. Today, we will take an in-depth look at the chmod command so that Linux permission management will no longer be your nightmare.
For directories, the function of the execution bit is to control whether to enter or pass the directory, not to control whether to list its contents. The combination of the read bit and the execute bit controls whether the contents of the directory are listed. The combination of the write bit and the execute bit allows the creation, deletion, and renaming of files in the directory.
The following uses examples to illustrate the problem: the main command is chmod
Ordinary users create the folder linuxidc, the default permission is 775
linuxidc@Ubuntu:~/linuxidc.com$ mkdir linuxidc linuxidc@ubuntu:~/linuxidc.com$ ls linuxidc linuxidc@ubuntu:~/linuxidc.com$ ls -l total 4 drwxr-xr-x 2 linuxidc linuxidc 4096 Feb 16 20:18 linuxidc linuxidc@ubuntu:~/linuxidc.com$ ls -l linuxidc/ total 0

Change the directory permissions to 700, and files can be listed and created in the directory
linuxidc@ubuntu:~/linuxidc.com$ chmod 700 linuxidc/ linuxidc@ubuntu:~/linuxidc.com$ uptime > linuxidc/uptime linuxidc@ubuntu:~/linuxidc.com$ ls -l total 4 drwx------ 2 linuxidc linuxidc 4096 Feb 16 20:22 linuxidc linuxidc@ubuntu:~/linuxidc.com$ ls -l linuxidc/ total 4 -rw-r--r-- 1 linuxidc linuxidc 61 Feb 16 20:22 uptime linuxidc@ubuntu:~/linuxidc.com$ cat linuxidc/uptime 20:22:23 up 13:22, 1 user, load average: 0.00, 0.08, 0.20

Change the directory permissions to 400. Details cannot be listed in the directory, CAT cannot be used, and files cannot be created
linuxidc@ubuntu:~/linuxidc.com$ chmod 400 linuxidc/ linuxidc@ubuntu:~/linuxidc.com$ ls -l linuxidc/ ls: cannot access 'linuxidc/uptime': Permission denied total 0 -????????? ? ? ? ? ? uptime linuxidc@ubuntu:~/linuxidc.com$ ls -l total 4 dr-------- 2 linuxidc linuxidc 4096 Feb 16 20:22 linuxidc linuxidc@ubuntu:~/linuxidc.com$ cat linuxidc/uptime cat: linuxidc/uptime: Permission denied linuxidc@ubuntu:~/linuxidc.com$ touch linuxidc/linuxmi touch: cannot touch 'linuxidc/linuxmi': Permission denied

Change the directory permissions to 100, the directory cannot be listed, the directory can be entered, files cannot be created, and files in Cat (of course the permissions of the file must be there, and you know its name, you cannot associate it)
linuxidc@ubuntu:~/linuxidc.com$ chmod 100 linuxidc/ linuxidc@ubuntu:~/linuxidc.com$ ls -l total 4 d--x------ 2 linuxidc linuxidc 4096 Feb 16 20:22 linuxidc linuxidc@ubuntu:~/linuxidc.com$ ls -l linuxidc/ ls: cannot open directory 'linuxidc/': Permission denied linuxidc@ubuntu:~/linuxidc.com$ ls -l linuxidc/uptime -rw-r--r-- 1 linuxidc linuxidc 61 Feb 16 20:22 linuxidc/uptime linuxidc@ubuntu:~/linuxidc.com$ cd linuxidc/ linuxidc@ubuntu:~/linuxidc.com/linuxidc$ ls -l ls: cannot open directory '.': Permission denied linuxidc@ubuntu:~/linuxidc.com/linuxidc$ cat uptime 20:22:23 up 13:22, 1 user, load average: 0.00, 0.08, 0.20 linuxidc@ubuntu:~/linuxidc.com/linuxidc$ touch linuxmi touch: cannot touch 'linuxmi': Permission denied

Change the directory permissions to 200. Listing, CAT, and file creation are not allowed in the directory.
linuxidc@ubuntu:~/linuxidc.com$ chmod 200 linuxidc/ linuxidc@ubuntu:~/linuxidc.com$ ls -l total 4 d-w------- 2 linuxidc linuxidc 4096 Feb 16 20:22 linuxidc linuxidc@ubuntu:~/linuxidc.com$ ls -l linuxidc/ ls: cannot open directory 'linuxidc/': Permission denied linuxidc@ubuntu:~/linuxidc.com$ cat linuxidc/uptime cat: linuxidc/uptime: Permission denied linuxidc@ubuntu:~/linuxidc.com$ touch linuxidc/linuxidc touch: cannot touch 'linuxidc/linuxidc': Permission denied

Change the directory permissions to 500, the directory can be listed, CAT can be used, but files cannot be created,
linuxidc@ubuntu:~/linuxidc.com$ chmod 500 linuxidc/ linuxidc@ubuntu:~/linuxidc.com$ ls -l total 4 dr-x------ 2 linuxidc linuxidc 4096 Feb 16 20:22 linuxidc linuxidc@ubuntu:~/linuxidc.com$ ls -l linuxidc/ total 4 -rw-r--r-- 1 linuxidc linuxidc 61 Feb 16 20:22 uptime linuxidc@ubuntu:~/linuxidc.com$ cat linuxidc/uptime 20:22:23 up 13:22, 1 user, load average: 0.00, 0.08, 0.20 linuxidc@ubuntu:~/linuxidc.com$ touch linuxidc/linuxidc.com touch: cannot touch 'linuxidc/linuxidc.com': Permission denied

Change the directory permissions to 300, the directory cannot be listed, but CAT (of course the permissions of the file must be there, and you know its name, you cannot associate it), you can create files,
linuxidc@ubuntu:~/linuxidc.com$ chmod 300 linuxidc/ linuxidc@ubuntu:~/linuxidc.com$ ls -l total 4 d-wx------ 2 linuxidc linuxidc 4096 Feb 16 20:22 linuxidc linuxidc@ubuntu:~/linuxidc.com$ ls -l linuxidc/ ls: cannot open directory 'linuxidc/': Permission denied linuxidc@ubuntu:~/linuxidc.com$ cat linuxidc/uptime 20:22:23 up 13:22, 1 user, load average: 0.00, 0.08, 0.20 linuxidc@ubuntu:~/linuxidc.com$ touch linuxidc/linux linuxidc@ubuntu:~/linuxidc.com$

Remarks: 700=rwx, 400=r, 100=x, 200=w, 500=rx, 300=wx
Through the introduction of this article, we have in-depth understanding and study of the commonly used file permission management command chmod in Linux. It provides detailed explanations on command syntax, permission types, digital representation and actual usage scenarios, which I believe will be very helpful for beginners. At the same time, it is recommended that you practice more and combine it with actual operations to deepen your understanding and mastery of file permissions. Correct permission management can ensure the security and stability of the system, and is also an indispensable part of operation and maintenance work!
The above is the detailed content of No longer be afraid of the chmod command, let Linux permission management no longer become your nightmare!. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

There are six ways to run code in Sublime: through hotkeys, menus, build systems, command lines, set default build systems, and custom build commands, and run individual files/projects by right-clicking on projects/files. The build system availability depends on the installation of Sublime Text.

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.

To install Laravel, follow these steps in sequence: Install Composer (for macOS/Linux and Windows) Install Laravel Installer Create a new project Start Service Access Application (URL: http://127.0.0.1:8000) Set up the database connection (if required)

Installing Git software includes the following steps: Download the installation package and run the installation package to verify the installation configuration Git installation Git Bash (Windows only)

Visual Studio Code (VSCode) is a cross-platform, open source and free code editor developed by Microsoft. It is known for its lightweight, scalability and support for a wide range of programming languages. To install VSCode, please visit the official website to download and run the installer. When using VSCode, you can create new projects, edit code, debug code, navigate projects, expand VSCode, and manage settings. VSCode is available for Windows, macOS, and Linux, supports multiple programming languages and provides various extensions through Marketplace. Its advantages include lightweight, scalability, extensive language support, rich features and version
