Han Shunping Linux 44--

Forty-four, rwx permissions

Basic introduction to permissions

  • Enter the command ls -l and the displayed content is as follows
    • -rwxrw-r-- 1 root 1213 Feb 2 09:39 abc
    • 0-9 digit description
      • Bit 0 determines the file type (d, -, l, c, b)        
        • l is a link, equivalent to a Windows shortcut
        • - Represents that the file is an ordinary file
        • d is a directory, which is equivalent to a windows folder
        • c is character files, mouse, keyboard
        • b is a block device, such as a hard disk
          • cd /dev/ directory to view

      • Bits 1-3 determine the owner (the owner of the file) who has the permissions for the file --User
      • Bits 4-6 determine that the group to which it belongs (same as the user group) has the permissions of the file--Group
      • Bits 7-9 determine that other users have permissions for the file --Other
  • rwx applies to files

  1. [ r ] stands for read: can be read and viewed
  2. [ w ] means writable (write): it can be modified, but it does not mean that the file can be deleted. The prerequisite for deleting a file is that you have write permission for the directory where the file is located before you can delete the file.
  3. [ x ] stands for execute: can be executed
  • rwx applies to directories

  1. [ r ] stands for read (read): it can be read, ls can view the directory contents
  2. [ w ] represents writeable (write): can be modified, create + delete + rename the directory within the directory
  3. [x] stands for executable (execute): you can enter the directory

45. Cases of permission description

  • The content displayed in the terminal ls -l is as follows:
    • -rwxrw-r-- 1 root root 1213 Feb 2 09:39 abc
      • 10 characters to determine what different users can do to the file
      • The first character represents the file type: -ldcb
      • The remaining characters are grouped in groups of 3 (rwx) read (r) write (w) execute (x)
      • The first group rwx: the file owner's permissions are read, write and execute
      • The second group rw-: The permissions of users in the same group as the file owner are read and write but not execute.
      • The third group r-: The permissions of other users who are not in the same group as the file owner are read but not write or execute.
    • The available numerical representation is r=4 w=2 x=1 so rwx=4+2+1=7
    • other instructions
      • 1 File: Number of hard links or Directory: Number of subdirectories
      • root user
      • root group
      • 1213 file size (bytes), if it is a folder, 4096 bytes are displayed
      • Feb 2 09:39 Last Modified
      • abc filename

Forty-six, modification authority

  • Basic instructions
    • Through the chmod command, you can modify the permissions of files or directories.
  • The first way: + , - , = change permissions
    • u: Owner g: All groups o: Others a: Everyone (sum of u, g, o)
    • chmod u=rwx, g=rx, o=x file/directory
    • chmod o+w file/directory name
    • chmod a=x file/directory name
  • Case presentation
    • Give the owner of the abc file read, write and execute permissions, give the group read and execute permissions, and give other groups read and execute permissions.
      • chmod u=rwx,g=rx,o=rx abc
    • Remove execute permissions for the owner of the abc file and add write permissions for the group
      • chmod u-x,g+w abc
    • Add read permission to all users of the abc file
      • chmod a+r abc
    • The second way: changing permissions through numbers
      • r=4 2=2 x=1   rwx=4+2+1=7
      • chmod u=rwx,g=rx,o=x file directory name
      • Equivalent to chmod 751 file directory name
      • Case presentation
        • Requirement: Change the permissions of the /home/abc.txt file to rwxr-xr-x, using the number method to achieve
          • In rwxr-xr-x, rwx is equal to 7, rx is equal to 5, and rx is equal to 5
            • chmod 755 /home/abc.txt

Forty-seven, modify the file owner and group

Modify file owner -chown

  • basic introduction
    • chown newowner file/directory change owner
    • chown newowner:newgroup file/directory changes the owner's group
    • -R If it is a directory, make all sub-files or directories under it recursive.
  • Case presentation
    • Please change the owner of the /home/abc.txt file to tom
      • chown tom /home/abc.txt
    • Please change the owner of all files and directories in the /home/test directory to tom
      • chown -R tom /home/test

Modify the group of the file/directory -chagrp

  • basic introduction
    • chgrp newgroup file/directory change group
  • Case presentation
    • Please change the group of the /home/abc.txt file to shaolin
      • group add shaolin
      • chgrp shaolin /home/abc.txt
    • Please modify all files and directories in the /home/test directory to shaolin
      • chgrp -R shaolin /home/test

Forty-eight, rights management application example 1

Best Practices - Cops and Bandits Games

police,bandit

jack,jerry:police

xh,xq:bandit

  1. Create group
    1. groupadd polic;
    2. groupadd bandit
  2. create user
    1. useradd -g polic jack;
    2. useradd -g polic jerry;
    3. useradd -g bandit xh;
    4. useradd -g bandit xq;
  3. Jack creates a file. He can read r and write w. People in this group can read it, but other groups have no permissions.
    1. First log in with jack and create the file vim jack.txt
    2. After entering, press i to enter the editing mode, enter hello and then ESC, then enter: wq! to save
  4. jack modifies the file so that other people in the group can read it and people in this group can read and write.
    1. chmod o=r,g=r jack.txt
  5. xh Go to the police and see if you can read and write
    1. usermod -g polic xh
    2. First log in as the root user with greater permissions, and then make modifications.
  6. Test: see if xh can read and write
    1. Conclusion: If you want to operate the files in the directory, you need to have the corresponding permissions on the directory.

Forty-nine, rights management application example 2

  1. Create two groups (fairy (sx), monster (yg))
    1. groupadd sx
    2. groupadd yg
  2. Create four users (Tang Monk, Wukong, Bajie, Sha Monk)
    1. useradd ts
    2. useradd wk
    3. useradd bj
    4. useradd ss
  3. set password
    1. passwd ts
      1. Set password 123
    2. passwd wk
      1. Set password 123
    3. passwd bj
      1. Set password 123
    4. passwd ss
      1. Set password 123
  4. Put Wukong and Bajie into monsters, Tang Monk and Sha Monk into immortals
    1. Change the group the user belongs to: usermod -g group name user name
    2. usermod -g yg wk
    3. usermod -g yg bj
    4. usermod -g sx ts
    5. usermod -g sx ss
  5. Use Wukong to create a file (monkey.java. This file should output i am monkey)
    1. First log in as Wukong user
    2. pwd View absolute path
    3. vim monkey.java create file
    4. Press i to enter editing mode and enter i am monkey,
    5. Press ESC to exit editing mode, enter: wq! Save
  6. Give Bajie a rw permission
    1. Bajie and Wukong are in the same group yg. The ll above shows that the group already has read permission, so just add another write permission.
    2. Add write permissions to the group where the file belongs: chmod g+w monkey.java
  7. Bajie modified monkey.java and added a sentence (i am pig)
    1. First log in with the Bajie username and use pwd to view the absolute path.
    2. cd /home/wk enters Wukong's directory, the permissions are insufficient
    3. For the group where the monster belongs, wk does not give any permissions to other group members.
    4. Add read, write, and execute permissions to other members of the group through wk
      1. chmod g+r+w+x wk
      2. Now members of the same group as wk have read and write permissions to the group yg.
      3. Log in with Bajie's username and now have permission to enter Wukong's directory.
      4. cd /home/wk
      5. Enter the file to edit vim monkey.java
      6. Press i to enter the editing mode, enter the input content i am pig, press ESC to exit the editing mode, enter: wq! to save
  8. Tang Monk Sha Seng does not have permission to this file
  9. Put Drifting in the Yokai group
    1. You cannot log in to Sha Monk and modify your own group with your username.
    2. Can only be modified by logging in as root
    3. Change the group the user belongs to: usermod -g group name user name
    4. Log in as root user and enter usermod -g yg ss
    5. Use the id username to check and find that you are already in the monster group.
    6. After modifying the group, you need to log in again as the Sha Seng user in time to enter the monster group.
  10. Let Sha Monk modify the file monkey and add a sentence: "I am Sha Monk, I am a monster"
    1. Enter the file vim monkey.java
    2. Enter i to enter edit mode
    3. Input content: I am Sha Monk, I am a monster
    4. Press ESC to exit editing mode, enter: wq! to save

50. Permission management application example 3

  1. Detailed discussion and testing of folder rwx
    1. x: Indicates that you can enter the directory, such as cd
    2. r: Indicates that ls can be used to display the contents of the directory.
    3. w: Indicates that files can be deleted or created in this directory

Fifty-two, crond quick start

crond task scheduling

crontab to set the timed task,

  • Overview

    • Task scheduling: refers to specific commands or programs executed by the system at a certain time
    • Task scheduling classification: System work: Some important tasks must be performed repeatedly, such as virus scanning and other individual user tasks. Other users may want to perform certain programs, such as backup of the MySQL database.

  • basic grammar
    • crontab [options]
  • Quick start

    • Set task scheduling file: /etc/crontab

    • Set up personal task scheduling and execute the crontab -e command

    • Then enter the task into the schedule file

    • For example: */1 * * * * ls -l /etc/ > /tmp/to.txt command, which means to execute the ls -l /etc/ > /tmp/to.txt command every minute of every hour

    • Parameter details

      • Description of the 5 placeholders

      • First enter crontab -e and press Enter

      • Press i to enter edit mode and enter */1 * * * * ls -l /etc/ > /tmp/to.txt

      • Then ESC to exit the editing mode, enter: wq! to save. If the creation is successful, there will be a prompt of installing new crontab.

      • cd /tmp/ to enter the tmp directory and then use ls to view it, and use the ll command to view it.

      • You will find that there is a to.txt file in the directory, which was generated a minute ago.

Fifty-three, crond time rules

crond task scheduling

Description of special symbols 

Specific event execution task case

Fifty-four, crond application examples

crond task scheduling

  • Applications
    • Case 1: Every one minute, append the current date information to the /tmp/mydate file
      • */1 * * * * date >> /tmp/mydate
    • Case 2: Append the current date and calendar to the /home/mycal file every one minute
      • Write a script file vim /home/my.sh and write the content 
      • Press i to enter editing mode. After completing the input, press ESC and enter: wq! to save.

    • Case 3: Back up the mysql database testdb to a file at 2:00 a.m. every day.
      • Tip: The command is mysqldump -u root -p password database >> /home/db.bak
  • crond related instructions

    • conrtab -r : terminate task scheduling
    • crontab -l: list which tasks are currently scheduled
    • service crond restart  [restart task scheduling]

Guess you like

Origin blog.csdn.net/z972065491/article/details/132360546