Second, Shell file permissions and script execution

Source: Internet
Author: User
Tags parent directory

I. Understanding rights and User management 1. View Permissions Permission Type:1, R read 2, W write 3, x executable Linux Users1. Owner (U) 2, owning Group (g) (All users of owner and owner Group) 3, other User (O) (all users of other groups (including file owner) 4, all users (a) interpretation of file permissions
File type Owner permissions belong to group permissions other user Rights owner user group file size creation time file name
[[Email protected] ~]# ll Total dosage --RW-------.1Root root1752May A xx: inanaconda-ks.cfg-rw-r--r--.1Root root44184May A xx: - Install. Log[[email protected]~]#Head-1/etc/passwdroot:x:0:0: root:/root:/bin/Bash[[email protected]~]#Head-1/etc/grouproot:x:0: [[email protected]~]#Cat/etc/grouproot:x:0: bin:x:1: Bin,daemon
ii. Users and Permissions 1. User Management (1), User view
ID  Username

(2), user add

Useradd  username

Create a user, and a new user group is generated, and the user belongs to that group

(3), user delete
Userdel  -  R  username
2. User GroupUser-to-group relationships: (1), add users to the group
ID Test2uid=501(test2) gid=501(test2) group =501~]# gpasswd-a test2 root           ID Test2uid=501(test2) gid=501(test2) group =501(test2),0(Root)  #test2同时属于两个组
Two groups, two groups of permissions are available, that is, the sum of two groups of permissions (2), delete the user in the group
[Email protected] ~]# gpasswd-d test2 rootremoving user test2 from group root
3. Permission Assignment12th modification of user permissions on a file (1), chmod rights AssignmentA, letter permission assignment chmod u+x file chmod u-x file (set permissions individually for users in this way.) )b, the digital permissions chmod 755 file number corresponding permissions are as follows: R 4 W 2 x 1755 rwx r-x r-x754 rwx r-x R -Default 644 (Use the Word method when all user permissions are modified)Disadvantage: You cannot assign a fine-grained permission to a user   (2), ACLPermission Refinement requirements 1, root file rw-2, root file r--3, other file r--4, user1 file rw5, user2 file rx6, User3 file wx (cannot view, but can write) 7, User4 F Ile rwx (rwx only has permissions on the content and cannot be deleted) ACL permission assignment:1. Setfacl Set file permissions
Setfacl-
2. Getfacl View File permissions
3, delete file permissions setfacl-x user:user4 file01.txt4, empty file permissions Setfacl-b file01.txt Erase all permissions to the file (restore the original state of the file permissions: 644) 5, create and delete   In addition to file permissions: #需要对目录设置acl权限即可 setfacl-m u:user4:rwx mnt/Note: dr-xr-xr-x. 2 root root 4096 May 14:19 mnt switch to directory for an instant requires the directory's X permission, otherwise you cannot switch directories. 6. How to set ACL permissions on directories and subdirectories and files setfacl-m u:user4:rwx-r/mnt/r parameter represents recursion 7, subdirectories added later in the directory, and how files inherit permissions from parent directory method one: Setfacl-m u:us Er4:rwx-r/mnt/Cumbersome (application example: Web site file Management) method two: Setfacl-m D:u:user4:rwx-r/mnt/d on behalf of default permissions, will inherit the tacit Permissions user permissions on programs, commands(3), sudo
Set user Execute permissions on commands-visodo:1, settings: # visudouser4 Localhost=/usr/sbin/useradd,/usr/sbin/userdel 2, using sudo authorization command with password $ sudo/usr/ Sbin/useradd user5$ sudo/usr/sbin/userdel-r User5 3, using the password-free sudo authorization command (use scenario: Enter a command in the script) $ sudo/usr/sbin/useradd user6$ sudo /usr/sbin/userdel-r user6 setup form: User5 all=nopasswd:/usr/sbin/useradd,/usr/sbin/userdelsudo all=nopasswd:/usr/sbin/ Userdel-r User4 III, S Hell file permissions and script execution 1. Shell Script(1), use: To complete a specific, more complex system management tasks (2), format: Centralized storage of multiple Linux commands, plain text files (3), execution mode: In the order of the default execution of interpretation execution 2. Write executable shell scripts(1), create a script file (2) containing the execution statement, #脚本文件中包含的内容 run environment setting: #! /bin/bash Comment Information: Descriptive text starting with # executable Linux command line (3), add executable permission for script file 3. How to execute shell scripts:(1), bash test.sh #不需要写解析器, and do not need to set execution permissions (2),./test.sh #需要写解析器, you need to set execution permissions to the script 4. A shell script example:
#!/bin/Bash#tesh.SH Echo 'disk space:'EchoDF-ThEchoEcho 'Free Space:' Free-mEchoEcho 'Users:' forIinch'Ls/home' Do    ID-u $i Done
Run the shell script: directly execute a script file with X permissions: for example:./test.sh executes the script content using the specified interpreter program: For example: Bash test.sh, SH test.sh 5. Shell Script Example: Clean the public shared directory of the FTP server every Friday 17:30Check the/var/ftp/pub/directory, append a detailed list of all its subdirectories and files, then save the time information to the/var/log/pubdir.log file, and then empty the directory yum-y install vsftpd*
#!/bin/date >>/var/log/ls -lhr/var/ftp/pub >>/var/log/  rm -rf/var/FTP/pub
After the command is executed, it can be added to the task plan:
Crontab-e   
To view a task schedule:
Crontab-l

Second, Shell file permissions and script execution

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.