Use command-line tools to update permissions to a set of files.
Outcomes
Modify file ownership and permissions.
Use sudo privileges to run commands as a privileged user.
As the student user on the workstation machine, use the lab command to prepare your environment for this exercise, and to ensure that all required resources are available.
[student@workstation ~]$ lab start users-review
Instructions
Set the student user and the student group as owners of the /SalesTeam directory and its contents.
If required, then use the student user sudo privilege to change the ownership.
Use student as the password for the student user.
View the ownership of the /SalesTeam directory.
[student@workstation ~]$ ls -ld /SalesTeam/
drwxr-xr-x. 2 root root 33 Nov 6 00:51 /SalesTeam/The directory is owned by the root user, so the student user cannot modify the directory ownership.
Review the student user's sudo privileges.
Use student as the password for the student user.
[student@workstation ~]$sudo -l[sudo] password for student:student...output omitted... User student may run the following commands on workstation: (ALL) ALL(root) /bin/chown * /SalesTeam(ALL) NOPASSWD: /usr/local/lib/lab-*, /usr/local/lib/demo-*, /bin/curl, /bin/chmod
The student user can impersonate the root user to use the chown command on the /SalesTeam directory.
Use the student user sudo privilege to change the ownership of the /SalesTeam directory and its contents.
Set student as the user owner and the group owner.
Make sure to use the recursive option of the chown command to modify the directory contents.
[student@workstation ~]$ sudo chown -R student:student /SalesTeam/Review the ownership of the /SalesTeam directory.
[student@workstation ~]$ ls -ld /SalesTeam/
drwxr-xr-x. 2 student student 33 Nov 6 00:51 /SalesTeam/Create the meeting-highlights.txt file in the /SalesTeam directory.
Set read and write permissions to the student user and to the student group.
Do not set permissions for the others user set.
Create the meeting-highlights.txt file in the /SalesTeam directory.
[student@workstation ~]$ touch /SalesTeam/meeting-highlights.txtSet read and write permissions to the student user and the student group on the meeting-highlights.txt file.
Do not set permissions for the others user set.
[student@workstation ~]$ chmod 0660 /SalesTeam/meeting-highlights.txtReview the file permissions.
[student@workstation ~]$ ls -l /SalesTeam/meeting-highlights.txt
-rw-rw----. 1 student student 0 Nov 6 00:59 /SalesTeam/meeting-highlights.txtSet permissions on the generate_reports.sh script so that only the student user can execute the file.
Maintain any other existing permissions.
Execute the generate_reports.sh script.
Verify that the generate_reports.sh script creates three quarterly reports with the xls extension in the /SalesTeam directory.
Review the generate_reports.sh script file permissions.
[student@workstation ~]$ ls -l /SalesTeam/generate_reports.sh
-rw-r--r--. 1 student student 47 Nov 6 01:03 /SalesTeam/generate_reports.shSet execute permissions for the student user.
[student@workstation ~]$chmod 0744 /SalesTeam/generate_reports.sh[student@workstation ~]$ls -l /SalesTeam/generate_reports.sh-rwxr--r--. 1 student student 47 Nov 6 01:03 /SalesTeam/generate_reports.sh
Execute the generate_reports.sh script.
[student@workstation ~]$ /SalesTeam/generate_reports.shVerify that the generate_reports.sh script created the quarterly reports.
[student@workstation ~]$ ls /SalesTeam/
...output omitted...
Report2023Q1.xls Report2023Q2.xls Report2023Q3.xls
...output omitted...