Linux Permissions Essentials: chmod, chown, and umask Quiz Quiz

Explore your understanding of Linux file permissions, focusing on key commands like chmod, chown, and umask. This quiz is designed to help users grasp fundamental concepts and typical scenarios encountered in Linux security and access control.

  1. Understanding chmod Syntax

    Which command correctly changes the permissions of 'example.txt' to read-only for everyone?

    1. chmod 444 example.txt
    2. chmod 777 example.txt
    3. chmod 755 example.txt
    4. chmod 111 example.txt

    Explanation: The command 'chmod 444 example.txt' sets read permissions for user, group, and others, making the file read-only. 'chmod 777' gives all permissions to everyone, which is not read-only. 'chmod 755' gives full permissions to the owner and read-execute to others. 'chmod 111' only allows execute permissions, not read.

  2. Modifying Owner with chown

    Which command will change the owner of 'script.sh' to the user 'alex'?

    1. chown alex script.sh
    2. chmod alex script.sh
    3. umask alex script.sh
    4. ownerchange alex script.sh

    Explanation: 'chown alex script.sh' properly changes the file's owner to 'alex'. 'chmod' is used for permissions, not ownership. 'umask' manages default permissions, and 'ownerchange' is not a valid command. Only the 'chown' command is correct in this context.

  3. Understanding umask Defaults

    If the umask is set to 022, what will be the default permissions for newly created files?

    1. 644
    2. 666
    3. 777
    4. 600

    Explanation: A umask of 022 removes write permissions for group and others, resulting in a default of 644 (rw-r--r--). '666' would be used if umask was 000. '777' is rarely the default and would be dangerous. '600' removes more permissions than a 022 umask would.

  4. Symbolic chmod Usage

    Which symbolic chmod command will remove execute permissions from others on 'program'?

    1. chmod o-x program
    2. chmod o+x program
    3. chmod -x program
    4. chmod x-o program

    Explanation: 'chmod o-x program' removes execute permission 'x' from 'others'. 'chmod o+x' would add execute permission, not remove it. 'chmod -x' is not the correct syntax, and 'chmod x-o' is not a valid option. The 'o-x' form is correct for this operation.

  5. Checking Current File Permissions

    Which command displays the permissions of all files in a directory in long format?

    1. ls -l
    2. chmod -l
    3. showperm
    4. lsperm

    Explanation: 'ls -l' lists files with detailed information, including permissions. 'chmod -l' is not a valid option. 'showperm' and 'lsperm' do not exist as commands in standard distributions. Only 'ls -l' correctly displays the required details.

  6. Applying Permissions Recursively

    Which option allows you to recursively change permissions in subdirectories using chmod?

    1. -R
    2. -A
    3. -B
    4. -F

    Explanation: The '-R' option applies changes recursively to directories and their contents. '-A', '-B', and '-F' are not valid chmod options for recursion. Only '-R' is recognized for recursive operations in chmod.

  7. Changing Both Owner and Group

    What is the correct way to change both the owner to 'pat' and group to 'dev' for a file named 'report.log'?

    1. chown pat:dev report.log
    2. chmod pat:dev report.log
    3. chgrp pat:dev report.log
    4. chown dev:pat report.log

    Explanation: 'chown pat:dev report.log' changes the owner to 'pat' and the group to 'dev' in one command. 'chmod' is only for permissions, not owners or groups. 'chgrp' changes only the group, not the owner. 'chown dev:pat' would swap the order, making 'dev' the owner and 'pat' the group, which is incorrect as per the question.

  8. Octal Permissions Meaning

    What do the octal permissions '755' provide on a directory?

    1. Owner can read, write, and execute; group and others can read and execute
    2. Everyone can read and write
    3. Only the owner can access the directory
    4. Owner and group can read, write, and execute; others can only read

    Explanation: '755' allows the owner full access and gives group and others read and execute rights. 'Everyone can read and write' would be '666' or similar. 'Only the owner can access' describes '700'. 'Owner and group can read, write, and execute; others can only read' describes '774'.

  9. Execute Bit Usage

    Why must a script file have the execute permission set for a user to run it directly?

    1. Without execute, the operating system prevents file execution
    2. Read permission alone is enough to run the script
    3. Write permission allows execution
    4. No permissions are needed to run files

    Explanation: The OS checks for execute permissions before allowing a file to be run directly. Read permission lets you read contents, not run the file. Write allows changes but not execution. You need at least execute permission to run a script, so the other answers are incorrect.

  10. umask and Directories

    If umask is 027, what will the default permissions be for a new directory?

    1. 750
    2. 777
    3. 700
    4. 755

    Explanation: A default directory permission is '777'. Subtracting umask '027' removes write from group and all permissions from others, leaving '750'. '777' ignores the umask. '700' would result from umask '077'. '755' leaves write for the group, which is not the case here.

  11. Identifying chown Functionality

    What is the main purpose of the chown command in Linux?

    1. To change the owner and/or group of a file
    2. To change permissions on a file
    3. To create new files
    4. To hide files from other users

    Explanation: 'chown' changes the file's owner and/or group. Changing permissions is done with 'chmod', not 'chown'. Creating files does not involve 'chown'. Hiding files from others can involve permissions, but 'chown' does not do this directly.

  12. Special Meaning for '0' in chmod

    What does using '0' as an octal value in chmod mean for that user class?

    1. No permissions: read, write, or execute are removed
    2. Only execute is allowed
    3. Only write is allowed
    4. All permissions are granted

    Explanation: '0' means no permissions for that user class. Only execute equals '1', only write equals '2', and full permissions is '7'. Granting all permissions requires '7', not '0'.

  13. Adding Permissions with Symbolic Mode

    Which command adds write permission for the group on file 'notes.txt'?

    1. chmod g+w notes.txt
    2. chmod w+g notes.txt
    3. chmod +g+w notes.txt
    4. chmod w-g notes.txt

    Explanation: 'chmod g+w notes.txt' adds write permission for the group. 'chmod w+g' and 'chmod +g+w' are invalid syntaxes. 'chmod w-g' tries to remove write from group but is written incorrectly. Only the first option works as intended.

  14. umask Impact on File Creation

    With a umask of 0022, what happens to the write permissions for 'others' on new files?

    1. Write permission for others is removed
    2. Write permission for others is granted
    3. All permissions are granted
    4. Only the owner loses write permission

    Explanation: A umask of 0022 removes write permissions from the group and others. Granting write to others would be a umask of 0000 or less restrictive. Granting all permissions is not umask's function, and owner's write is not affected by 0022.

  15. Removing Permissions

    How would you remove the write permission from all users for the file 'data.csv'?

    1. chmod a-w data.csv
    2. chmod a+w data.csv
    3. chmod a=x data.csv
    4. chmod w-a data.csv

    Explanation: 'chmod a-w data.csv' removes write permission for all users. 'chmod a+w' adds, not removes, write permission. 'chmod a=x' sets permissions to execute only. 'chmod w-a' is incorrect syntax.

  16. Checking Default umask Value

    What command displays the current user's default umask value?

    1. umask
    2. ls -l
    3. chmod --umask
    4. whoami

    Explanation: 'umask' by itself shows the current default umask. 'ls -l' displays file permissions, not the umask. 'chmod --umask' is not a valid command. 'whoami' prints the current username, unrelated to umask.