ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • File permissions in Linux
    linux 2023. 2. 21. 10:20

    In Linux, file permissions are used to control access to files and directories. The file permission system is based on three types of permissions: read (r), write (w), and execute (x). These permissions can be assigned to three types of users: owner, group, and others.

    Here's a table of the permission options:

     

    PermissionDescription

    r Read permission. Allows the user to read the contents of a file or list the contents of a directory.
    w Write permission. Allows the user to modify the contents of a file or directory.
    x Execute permission. Allows the user to execute a file or enter a directory.
    - No permission. Indicates that the permission is not granted.

    Here's a table of the user types:

    User TypeDescription

    u Owner of the file or directory.
    g Group that the file or directory belongs to.
    o Other users who are not the owner or members of the group.
    a All users (equivalent to ugo).

     

    Linux file permission system can also be represented in numbers, which is known as octal notation. Each permission (read, write, execute) is assigned a numeric value as follows:

    • Read permission: 4
    • Write permission: 2
    • Execute permission: 1

     

    The permissions are then added together to create a three-digit number, where the first digit represents the permissions for the owner of the file, the second digit represents the permissions for the group associated with the file, and the third digit represents the permissions for everyone else.

    For example:

    • Read and write permission for owner, read permission for group and everyone else: 644 (4+2 for owner, 4 for group and everyone else)
    • Read, write, and execute permission for owner, read and execute permission for group and everyone else: 755 (4+2+1 for owner, 4+1 for group and everyone else)

     

    Here are some examples of how to set file permissions:

    • To give the owner of the file read, write, and execute permissions, and to give the group and others only read permission:
    chmod 744 file.txt

     

    This sets the file permissions to -rwxr--r--. The owner can read, write, and execute the file, and the group and others can only read the file.

    • To give the owner and group read, write, and execute permissions, and to give others no permission:
    chmod 770 directory/

     

    This sets the directory permissions to drwxrwx---. The owner and group can read, write, and execute the directory, and others have no permission to access the directory.

     

    'linux' 카테고리의 다른 글

    How to add and delete user in Linux  (0) 2023.02.21
    How to search file in Linux  (0) 2023.02.21
    Set default permissions for files and directories in Linux  (0) 2023.02.21
    What is inode  (0) 2023.02.20
    File addressing in Linux  (0) 2023.02.20
Designed by Tistory.