CompTIA Linux+ XK0-004 Exam Practice Questions

Edit Configuration Management File in Linux

Question

Ann, a Linux administrator, wants to edit a configuration management file.

When she opens the file to edit, her text editor reports that the file has been opened in read-only mode.

She then tries to edit the file as root by elevating via sudo and is still unable to save any changes.

The error message in her text editor says that the read-only option is set on the file.

Ann checks the permissions on the file and sees the following: -rw-rw-r-- 1 root wheel 30 Jun 13 15:38 infrastructure.yml Which of the following commands is the BEST option to allow her to successfully modify the file?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

D.

https://cets.seas.upenn.edu/answers/chmod.html

The permission string -rw-rw-r-- indicates that the file infrastructure.yml is owned by the root user and the wheel group, and the owner and members of the group have read and write permissions while others have only read permission.

When Ann opens the file in her text editor, she finds that the file is in read-only mode, which means that she can view the contents of the file but cannot make any changes to it. When she tries to edit the file as root by elevating via sudo, she still can't make any changes. The error message indicates that the read-only attribute is set on the file.

To allow Ann to successfully modify the file, she needs to change the file permissions or ownership. Let's examine each of the answer options:

A. chmod 600 infrastructure.yml: This command changes the file permissions to -rw-------, which means that the owner has read and write permissions and nobody else has any permissions. This would prevent anyone other than root from accessing or modifying the file, which may not be desirable in all cases. However, this command would allow Ann to modify the file as the root user, so it is a viable option.

B. chown root: infrastructure.yml: This command changes the file ownership to root:root, which means that the file is owned by the root user and the root group. However, this command does not change the file permissions, so Ann would still be unable to modify the file.

C. chattr -i infrastructure.yml: This command removes the immutable attribute from the file, which is a special attribute that prevents the file from being modified or deleted. However, this command requires the file to have the extended attributes (xattr) enabled, and it may not work on all file systems. Furthermore, it does not change the file permissions, so Ann would still be unable to modify the file.

D. chmod o+w infrastructure.yml: This command adds write permission for others (o) to the file, which changes the file permissions to -rw-rw-rw-. This would allow anyone to modify the file, which may not be desirable in all cases. Additionally, this command does not change the file ownership, so Ann would still need to elevate her privileges via sudo to modify the file.

Therefore, the BEST option to allow Ann to successfully modify the file while maintaining appropriate permissions is option A, chmod 600 infrastructure.yml. This command would give Ann the necessary permissions to modify the file as the root user, while preventing other users from accessing or modifying the file.