Home >Operation and Maintenance >Linux Operation and Maintenance >Detailed explanation of Linux backup and recovery and Linux file permissions
This article mainly introduces Linux backup and recovery and detailed explanation of Linux file permissions. Friends in need can refer to
Linux backup and recovery and Linux files. Detailed explanation of permissions
Overview
A system administrator rookie accidentally entered "chmod -R 777 /", which resulted in a huge The tragedy caused serious damage to the entire system. In daily management, we have many tools that can be used to back up file permissions, such as cp, rsync, etckeeper, etc. If you use this backup tool, then you really don't need to worry about changing file permissions.
But if you just want to temporarily back up the file permissions (not the file itself), for example: to prevent the contents of some directories from being overwritten, temporarily remove the write permissions of all files in the directory; or you are troubleshooting file permission problems During the process, you need to perform the chmod command on the file. In these cases, we can back up the original file permissions before they were changed and restore the original permissions later when we need it. In many cases, a full file backup is unnecessary if you just want to back up the file's permissions.
On Linux, it is actually easy to back up and restore file permissions using Access Control lists (ACLs). ACL defines the permissions of a single file on a POSIX-compatible file system based on different owners and groups.
##Install ACL Tool
On Debian, Ubuntu, Linux Mint$ sudo apt-get install aclOn CentOS, Fedora, On RHEL
$ sudo yum install acl
Back up the permissions of all files in the current directory (including subdirectories)
[xgj@entel2 shells]$ getfacl -R . > permissions.txt [xgj@entel2 shells]$ [xgj@entel2 shells]$ ll total 8 -rw-rw-r-- 1 xgj xgj 231 Jan 16 12:32 permissions.txt -rwxrwxr-x 1 xgj xgj 420 Jan 16 12:14 sys_info.shThis command will write all the ACL information of all files named permissions. txt file. The following is some directory information in the generated permissions.txt file
[xgj@entel2 shells]$ cat permissions.txt # file: . # owner: xgj # group: xgj user::rwx group::rwx other::r-x # file: sys_info.sh # owner: xgj # group: xgj user::rwx group::rwx other::r-x # file: permissions.txt # owner: xgj # group: xgj user::rw- group::rw- other::r--
Modify the permissions of a certain file
[xgj@entel2 shells]$ ll total 8 -rw-rw-r-- 1 xgj xgj 231 Jan 16 12:32 permissions.txt -rwxrwxr-x 1 xgj xgj 420 Jan 16 12:14 sys_info.sh [xgj@entel2 shells]$ chmod 777 sys_info.sh [xgj@entel2 shells]$ ll total 8 -rw-rw-r-- 1 xgj xgj 231 Jan 16 12:32 permissions.txt -rwxrwxrwx 1 xgj xgj 420 Jan 16 12:14 sys_info.sh
Restore the original permissions
[xgj@entel2 shells]$ setfacl --restore=permissions.txt [xgj@entel2 shells]$ ll total 8 -rw-rw-r-- 1 xgj xgj 231 Jan 16 12:32 permissions.txt -rwxrwxr-x 1 xgj xgj 420 Jan 16 12:14 sys_info.sh [xgj@entel2 shells]$
The above is the detailed content of Detailed explanation of Linux backup and recovery and Linux file permissions. For more information, please follow other related articles on the PHP Chinese website!