Check Linux file permissions

Reference text: How does the Linux system check file permissions

  • View the permissions of Linux files: ls -l file name

  • View the permissions of the linux folder: ls -ld folder name (directory)

  • Modify file and folder permissions: sudo chmod - (representative type) ××× (owner) ××× (group user) ××× (other users)

  • Commonly used commands to modify permissions:

    • sudo chmod 600 ××× (only the owner has read and write permissions)
    • sudo chmod 644 ××× (owner has read and write permissions, group users only have read permissions)
    • sudo chmod 700 ××× (only the owner has read, write and execute permissions)
    • sudo chmod 666 ××× (everyone has read and write permissions)
    • sudo chmod 777 ××× (everyone has read and write and execute permissions)
  • Linux view and modify file attributes and permissions 2009-12-24 17:27 I just used the ls -l_ command in the root directory of ubuntu, the following appears:

1 drwxr-xr-x 2 root root 4096 2009-01-14 17:34 bin
2 drwxr-xr-x 3 root root 4096 2009-01-14 14:36 boot
3 drwxr-xr-x 12 root root 14080 2009-07-20 14:13 dev
4 lrwxrwxrwx 1 root root 11 2009-01-14 10:05 cdrom -> media/cdrom

Let's take a look at what these file attributes mean:

  • First line:
    drwxr-xr-x 2 root root 4096 2009-01-14 17:34 bin
    0123456789
    File type codes: [d] – directory, [-] – file, [l] – link, [b] – available Store Peripherals, [c] – Serial Devices.
    File permission attributes: [ r ] – readable, [ w ] – writable, [ x ] – executable.
    0: represents a file or a directory, or other types (here d: means it is a directory)
    123: means the authority of the owner (here rwx: means the owner has readable, writable, and executable permissions)
    456: means the same Group user permissions (here rx means that users in the same group have readable and executable permissions)
    789: Indicates other user permissions (here rx means other users have readable and executable permissions)

  • The fourth line
    lrwxrwxrwx 1 root root 11 2009-01-14 10:05 cdrom -> media/cdrom
    The first letter: l stands for this link file, it is probably equivalent to the shortcut of windows!
    Owner Permissions: Read+Write+Execute=4+2+1=7
    Group Permissions: Read+Write=4+2=6
    Other User Permissions: Read=4

  • Let's take a look at several commands to modify file attributes:

    • chmod changes the permissions of a file
      • number type change

        1 sudo chmod 600 ××× (only the owner has read and write permissions)
        2 sudo chmod 644 ××× (the owner has read and write permissions, group users only have read permissions)
        3 sudo chmod 700 ××× ( Only the owner has read and write and execute permissions)
        4 sudo chmod 666 ××× (everyone has read and write permissions)
        5 sudo chmod 777 ××× (everyone has read and write and execute permissions) - xxx is the file name

        Three basic attributes: r, w, x digital representation: r:4, w:2, x:1
        Syntax: chmod [-R] xyz file or directory
        xyz is the addition of three groups of rwx attribute values ​​of the same group Numbers are added! If the attribute is [ -rwxrwx— ], then:
        owner = rwx = 4+2+1 = 7
        group = rwx = 4+2+1 = 7
        others = — = 0+0+0 = 0

        [root@test root]# ls –al .bashrc
        -rw-r–r– 1 root root 226 Feb 16 2002 .bashrc
        [root@test root]# chmod 777 .bashrc
        [root@test root]# ls –al . bashrc
        - rwxrwxrwx 1 root root 226 Feb 16 2002 .bashrc

      • The symbol type is changed.
        The nine attributes represent (1)user (2)group (3)others. Three groups of permissions can be represented by u, g, o! And a stands for all, that is, all.
        +(add)
        -(remove)
        =(set)

        Note : For the directory, you must have the execution permission to enter! A file's execute attribute will determine whether the file is executable, regardless of the file extension!

  • chgrp changes the group to which a file or directory belongs

    Syntax: chgrp group name file or directory such as chgrp [options] newgroup files/directorys

    [root@test root]# chgrp users tmp
    [root@test root]# ls –l
    drwx—— 2 root root 4096 Oct 19 11:43 drakx/
    drwx—— 2 root users 4096 Oct 19 21:24 tmp/
    [root@test root]# chgrp testing tmp
    chgrp: invalid group name `testing’ <==出错信息!

    Note : The group name to be changed must exist in /etc/group

  • chown Modify the master and group of the file or directory
    Syntax: chown [ -R ] username file or directory
    chown [ -R ] username: group name file or directory

    [root@test root]# chown test tmp
    [root@test root]# ls -l
    total 28
    drwx—— 2 root root 4096 Oct 19 11:43 drakx/
    drwx—— 2 test users 4096 Oct 19 21:24 tmp/
    [root@test root]# chown –R root:root tmp
    [root@test root]# ls –l
    drwx—— 2 root root 4096 Oct 19 11:43 drakx/
    drwx—— 2 root root 4096 Oct 19 21:24 tmp/

Guess you like

Origin blog.csdn.net/linux_tcpdump/article/details/131604330