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

mysql batch delete large amounts of data

mysql batch delete large amounts of data Assume t...

jQuery implements clicking left and right buttons to switch pictures

This article example shares the specific code of ...

Web page text design should be like smart girls wearing clothes

<br />"There are no ugly women in the w...

CentOS 8 officially released based on Red Hat Enterprise Linux 8

The CentOS Project, a 100% compatible rebuild of ...

Web Design Tutorial (4): About Materials and Expressions

<br />Previous Web Design Tutorial: Web Desi...

Query process and optimization method of (JOIN/ORDER BY) statement in MySQL

The EXPLAIN statement is introduced in MySQL quer...

Installation method of MySQL 5.7.18 decompressed version under Win7x64

Related reading: Solve the problem that the servi...

Analysis and solution of abnormal problem of loading jar in tomcat

Description of the phenomenon: The project uses s...

Nginx rewrite regular matching rewriting method example

Nginx's rewrite function supports regular mat...

MySQL cross-database transaction XA operation example

This article uses an example to describe the MySQ...

WeChat applet implements login interface

The login interface of WeChat applet is implement...