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.
Which command correctly changes the permissions of 'example.txt' to read-only for everyone?
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.
Which command will change the owner of 'script.sh' to the user 'alex'?
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.
If the umask is set to 022, what will be the default permissions for newly created files?
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.
Which symbolic chmod command will remove execute permissions from others on '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.
Which command displays the permissions of all files in a directory in long format?
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.
Which option allows you to recursively change permissions in subdirectories using chmod?
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.
What is the correct way to change both the owner to 'pat' and group to 'dev' for a file named '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.
What do the octal permissions '755' provide on a directory?
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'.
Why must a script file have the execute permission set for a user to run it directly?
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.
If umask is 027, what will the default permissions be for a new directory?
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.
What is the main purpose of the chown command in Linux?
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.
What does using '0' as an octal value in chmod mean for that user class?
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'.
Which command adds write permission for the group on file '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.
With a umask of 0022, what happens to the write permissions for 'others' on new files?
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.
How would you remove the write permission from all users for the file '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.
What command displays the current user's default umask value?
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.