Linux file/directory permissions and ownership management

Linux file/directory permissions and ownership management

1. Overview of file permissions and ownership

1. Access Rights

Read r: allows viewing file contents and displaying directory listings;

Write w: Allows modification of file contents, and allows creation, movement, and deletion of files or subdirectories in the directory;

Executable x: allows running programs and switching directories

2. Ownership

Owner: the user account that owns the file or directory;

Group: The group account that owns the file or directory;

3. View file permissions and ownership

Linux file/directory permissions and ownership management

4. chmod sets file permissions

The basic syntax format of the chmod command is as follows:

Linux file/directory permissions and ownership management

Application examples:

[root@centos01 ~]# touch 1.txt <!--Create 1.txt file-->
[root@centos01 ~]# ll 
Total dosage 8
-rw-r--r-- 1 root root 0 January 11 22:27 1.txt
-rw------. 1 root root 1572 Oct 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1603 10月23 23:36 initial-setup-ks.cfg
[root@centos01 ~]# chmod u+x ./1.txt <!--Add execution permission to the owner-->
[root@centos01 ~]# ll
Total dosage 8
-rwxr--r-- 1 root root 0 January 11 22:27 1.txt
-rw------. 1 root root 1572 Oct 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1603 10月23 23:36 initial-setup-ks.cfg
[root@centos01 ~]# chmod ux,g+x,o+w 1.txt  
<!--The owner user cancels the execute permission, the group adds the execute permission, and other users add the write permission-->
[root@centos01 ~]# ll
Total dosage 8
-rw-r-xrw- 1 root root 0 January 11 22:27 1.txt
-rw------. 1 root root 1572 Oct 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1603 10月23 23:36 initial-setup-ks.cfg
[root@centos01 ~]# chmod 755 1.txt <!--Add 755 permissions (rwxr-xr-x) -->
[root@centos01 ~]# ll
Total dosage 8
-rwxr-xr-x 1 root root 0 January 17 02:36 1.txt
-rw------. 1 root root 1572 Oct 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1603 10月23 23:36 initial-setup-ks.cfg

5. chown setting file ownership

The basic syntax format of the chown command is as follows:

Linux file/directory permissions and ownership management

Application examples:

[root@centos01 ~]# chown bob 1.txt <!--1.txt sets the owner-->
[root@centos01 ~]# ll
Total dosage 8
-rwxr-xr-x 1 bob root 0 January 17 02:36 1.txt
-rw------. 1 root root 1572 Oct 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1603 10月23 23:36 initial-setup-ks.cfg
[root@centos01 ~]# chown :benet 1.txt <!--1.txt sets the group -->
[root@centos01 ~]# ll
Total dosage 8
-rwxr-xr-x 1 bob benet 0 Jan 17 02:36 1.txt
-rw------. 1 root root 1572 Oct 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1603 10月23 23:36 initial-setup-ks.cfg
[root@centos01 ~]# chown bob:benet 1.txt <!--1.txt sets the owner and group -->
[root@centos01 ~]# ll
Total dosage 8
-rwxr-xr-x 1 bob benet 0 Jan 17 02:36 1.txt
-rw------. 1 root root 1572 Oct 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1603 10月23 23:36 initial-setup-ks.cfg
<!---->

2. Directory permissions and ownership

1. Access Rights

Linux file/directory permissions and ownership management

2. Ownership

Owner: the user account that owns the directory;

Group: The group account that owns the directory;

3. chmod sets directory permissions

The basic format of the chmod command to set directory permissions is as follows:

Linux file/directory permissions and ownership management

Application examples:

[root@centos01 ~]# chmod -R 755 benet/  
     <!--Loop setting the file or directory permissions under the benet directory to 755-->
[root@centos01 ~]# ll
Total dosage 8
-rw-r-xrw- 1 root root 0 January 11 22:27 1.txt
-rw------. 1 root root 1572 Oct 23 22:37 anaconda-ks.cfg
drwxr-xr-x 3 root root 18 January 11 22:39 benet
-rw-r--r--. 1 root root 1603 10月23 23:36 initial-setup-ks.cfg

4. chown sets the ownership of the directory

The basic format of the chown command to set directory ownership is as follows:

Linux file/directory permissions and ownership management

Application examples:

[root@centos01 ~]# chown -R bob:benet benet/  
  <!--Loop setting the user in the benet directory to bob and the group to benet-->
[root@centos01 ~]# ll
Total dosage 8
-rw-r-xrw- 1 root root 0 January 11 22:27 1.txt
-rw------. 1 root root 1572 Oct 23 22:37 anaconda-ks.cfg
drwxr-xr-x 3 bob benet 18 January 11 22:39 benet
-rw-r--r--. 1 root root 1603 10月23 23:36 initial-setup-ks.cfg

3. Permission mask umask

1. The role of umask

Controls the permissions of newly created files or directories. The default permissions minus the umask permissions are the permissions of newly created files or directories.

2. Set umask

umask 022

3. Check umask

umask

4. Application examples:

[root@centos01 ~]# umask <!--View umask-->
0022
[root@centos01 ~]# umask 000 <!--Set umask to 000-->
[root@centos01 ~]# umask <!--Verify whether the setting is successful-->
0000
[root@centos01 ~]# touch 2.txt <!--Create a new file-->
[root@centos01 ~]# ll
Total dosage 8
-rwxr-xr-x 1 bob benet 0 Jan 17 03:48 1.txt
-rw-rw-rw- 1 root root 0 January 17 03:48 2.txt <!-- View permissions -->
-rw------. 1 root root 1572 Oct 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1603 10月23 23:36 initial-setup-ks.cfg
[root@centos01 ~]# umask 022 <!--Set umask to 022-->
[root@centos01 ~]# umask <!--View umask-->
0022
[root@centos01 ~]# touch 3.txt <!--Create a new file again-->
[root@centos01 ~]# ll
Total dosage 8
-rwxr-xr-x 1 bob benet 0 Jan 17 03:48 1.txt
-rw-rw-rw- 1 root root 0 January 17 03:48 2.txt
-rw-r--r-- 1 root root 0 January 17 03:49 3.txt <!-- Check the permissions, obviously different -->
-rw------. 1 root root 1572 Oct 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1603 10月23 23:36 initial-setup-ks.cfg

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • A brief analysis of common Linux file management commands
  • Detailed explanation of Linux file management
  • Sharing of Linux operating system file manager
  • Linux file and user management practice
  • Summary of Linux file directory management commands
  • Detailed steps for Linux account file control management
  • Some Linux file permission management methods you may not know
  • Detailed explanation of Linux file permissions and directory management
  • Linux du command to view folder sizes and sort in descending order
  • How to retrieve file contents using grep command in Linux
  • Detailed application of command get to download files and put to upload files in Linux ftp command line
  • Linux commands to delete folders and files (forced deletion including non-empty files)
  • Linux file management command example analysis [permissions, create, delete, copy, move, search, etc.]

<<:  Detailed explanation of how components communicate in React

>>:  MySQL download and installation details graphic tutorial

Recommend

JavaScript implements three common web effects (offset, client, scroll series)

Table of contents 1. Element offset series 2. Ele...

MySQL tutorial data definition language DDL example detailed explanation

Table of contents 1. Introduction to the basic fu...

What is the use of the enctype field when uploading files?

The enctype attribute of the FORM element specifie...

Native JS to achieve directory scrolling effects

Here is a text scrolling effect implemented with ...

Application of anchor points in HTML

Set Anchor Point <a name="top"><...

Summary of various uses of JSON.stringify

Preface Anyone who has used json should know that...

HTML&CSS&JS compatibility tree (IE, Firefox, Chrome)

What is a tree in web design? Simply put, clicking...

Use CSS to implement special logos or graphics

1. Introduction Since pictures take up a lot of s...

Implementation of grayscale release with Nginx and Lua

Install memcached yum install -y memcached #Start...

Detailed explanation of the mysql database LIKE operator in python

The LIKE operator is used in the WHERE clause to ...

Code analysis of user variables in mysql query statements

In the previous article, we introduced the MySQL ...