Linux LPIC-1 Lab Guide PDF
Linux LPIC-1 Lab Guide PDF
Table of Contents
Topic 1: Performing Basic Linux Tasks .......................................................................................... 5
Lab 1-1: Entering Shell Commands ........................................................................................................5
Lab 1-2: Accessing Help in Linux ............................................................................................................9
Topic 2: Managing Users and Groups......................................................................................... 11
Lab 2-1: Assuming Superuser Privileges ............................................................................................... 11
Lab 2–2: Creating User Accounts ......................................................................................................... 13
Lab 2-3: Modifying User Accounts ....................................................................................................... 14
Lab 2-4: Deleting a User Account ......................................................................................................... 16
Lab 2-5: Creating, Modifying, and Deleting Groups .............................................................................. 17
Lab 2-6: Querying Users and Groups.................................................................................................... 19
Lab 2-7: Configuring Account Profiles .................................................................................................. 20
Topic 3: Managing Permissions and Ownership ......................................................................... 21
Lab 3-1: Modifying File and Directory Permissions .............................................................................. 21
Lab 3-2: Modifying Default Permissions .............................................................................................. 23
Lab 3-3: Modifying File and Directory Ownership ................................................................................ 24
Lab 3-4: Configuring SGID Permissions and Sticky Bits ......................................................................... 25
Lab 3-5: Setting the Immutable Flag on a File ...................................................................................... 26
Lab 3-6: Configuring ACLs .................................................................................................................... 27
Topic 4: Managing Storage ........................................................................................................ 28
Lab 4-1: Creating Partitions ................................................................................................................. 28
Lab 4-2: Managing Logical Volumes ..................................................................................................... 30
Lab 4-3: Mounting File Systems ........................................................................................................... 32
Lab 4-4: Managing File Systems ........................................................................................................... 34
Lab 4-5: Navigating the Linux Directory Structure ................................................................................ 36
Lab 4-6: Tracking Storage Space Usage ................................................................................................ 37
Lab 4-7: Configuring Storage Quotas ................................................................................................... 38
Topic 5: Managing Files and Directories .................................................................................... 40
Lab 5-1: Creating Text Files .................................................................................................................. 40
Lab 5-2: Editing Text Files .................................................................................................................... 41
Lab 5-3: Searching for Files .................................................................................................................. 43
Lab 5-4: Reading Files .......................................................................................................................... 44
Lab 5-5: Manipulating Files and Directories ......................................................................................... 46
Lab 5-6: Processing Text Files .............................................................................................................. 48
SCENARIO
As a result of your earlier discussion with the IT team at Develetech, your CTO is becoming more
and more convinced of the viability of switching the company's server infrastructure to Linux. The
CTO wants you to become more familiar with using Linux, and he suggests doing so by booting up a
test machine and trying it out. So, you'll start by entering some basic commands at the Bash shell to
get a feel for the Linux environment.
________________________________________________________________________________
The name of the file or folder is on the right. The last modified date and time is to the left of
the name, and to the left of that is the size of the file or folder (in bytes). Most of the other
fields relate to permissions and ownership.
c) Enter su - root
d) At the Password prompt, enter Pa22w0rd
e) Verify that your prompt has changed to [root@localhost ~]#
You are now logged in as the root user, the user with the highest level of privileges
(superuser).
f) Enter cat /var/log/boot.log and verify that you can now read the file.
g) Enter exit to log out as root and log back in to your regular student account.
SCENARIO
In order to be useful, Linux must have tools with certain capabilities that will be useful to the
business. One of these capabilities is searching the contents of text files. This will come in handy for
administrators who need to efficiently analyze text files like system logs, automated scripts, etc., for
specific patterns. You'll need to find one or more Linux tools that can accomplish this and learn how
to use them. So, you'll consult various help resources to get acquainted with the appropriate tool(s).
________________________________________________________________________________
2. Look for a command that could help you search the contents of a text file.
a) Enter apropos search
b) Verify that multiple commands are listed in the output, each of which includes the
c) term "search" in its name or brief description.
d) You could try to pick out the appropriate command from these results, but changing your
search might narrow them down.
e) Enter clear to clear the screen.
f) Enter apropos pattern
g) Verify that you receive fewer results
3. Looking at these results, which command(s) do you think would best fulfill the capabilities
that you're looking for?
Answers may vary, but one of the grep variants is likely the most appropriate command. The
awk command and its variants could be helpful, but appear to be more advanced.
4. Read the manual page for a command that could be what you're looking for.
a) Enter man grep
b) Verify that you see the manual page for the grep command.
c) Read the SYNOPSIS section to understand how to use the command.
d) Read the DESCRIPTION section to understand what the command does.
e) Navigate up and down the man page using the same keys as the less command.
f) Enter /case to search the man page for the term "case".
g) Press n to navigate to the next instance of the search term.
h) When you're at the end of the man page, press Shift+N to navigate to the previous instance
of the search term.
i) Read the description for the command option that has to do with case.
5. Given what you've read in the man page for grep so far, answer what youthink the
following command does: grep -i hello myfile
This command will return any lines in the file myfile that contain the text "hello", no matter
what case the text is in (case insensitive).
7. How confident are you that this command fulfills what you're looking for?
Answers may vary, but the grep command does generally meet your requirements.
However, this doesn't mean it's the only command, or the best command, for the job.
8. You still want to learn more about other commands that your team could use to search
the contents of a text file. Aside from the help options built into Linux, what other sources
can you consult in your research?
Answers may vary, but there is a wide variety of useful sources on the Internet that could
help you find what you're looking for. You could pose specific answers to Q&A sites like Stack
Exchange; ask discussion questions on newsgroups, mailing lists, and forums dedicated to
Linux support; consult supplementary and/or advanced documentation through a resource
like the Linux Documentation Project; or consult distro-specific documentation on the
relevant distro's website.
SCENARIO
While investigating Linux on behalf of Develetech, you have found multiple warnings about the
danger of using the root user administrative account. You are already familiar with the principle of
least privilege, which states that users should be granted only the level of access they need and no
more. You also know that this applies to administrators as well as to end users. The Develetech
security policy states that administrative privileges must be carefully controlled. You need to report
on how this requirement can be satisfied.
________________________________________________________________________________
3. Use the su - root command to elevate your credentials and context to those of root.
a) Enter su - root to change to root.
Caution: There is a space on each side of the hyphen.
b) Enter the Pa22w0rd password.
c) Enter pwd to confirm the present working directory.
Note that both your credentials and your context are those of the root user.
Note: If you use the su command without an argument, the system will default to the root
user. Example: su - assumes su - root
This grants the student account the ability to execute all commands without you having to
switch to the root user every time. It also prevents you from having to input your password.
This is for classroom convenience and is not suggested on a production environment.
Note: If you ever forget to add sudo to a privileged command, enter sudo !! to re-issue the
most recent command with superuser privileges.
f) Press Ctrl+C, and then enter the sudo shutdown -c command to interrupt the reboot.
SCENARIO
Managing user and group accounts in Linux will be a key administrative responsibility at Develetech.
Now that you have become comfortable with some basic Linux commands, you need to become
proficient at managing users. You'll start by creating some user accounts and viewing their defaults.
________________________________________________________________________________
Note: Newly created user accounts are appended to the bottom of this file.
4. Create new user accounts for Andrew Riley and Rachel Alexander named ariley and
ralexander, respectively.
a) Enter sudo useradd ariley
b) Enter sudo useradd ralexander
5. Create a new temporary user account for Rose Stanley named rstanley whose contract will
end on December 31, 2025.
a) Enter sudo useradd -e 2025/12/31 rstanley
b) Enter cat /etc/passwd and note the newly created account.
SCENARIO
Now that you have configured a few standard user accounts, you want to ensure the accounts exist.
You also need to set password requirements. In addition, you will investigate whether password
expirations can be configured and whether user accounts can be locked if users take a leave of
absence.
________________________________________________________________________________
Note: The !! symbols indicate that the account has a blank password and that users are not
allowed to log in as that account.
SCENARIO
You recognize that part of the user account lifecycle is the deletion of accounts that are no longer
needed on the system. You will use the userdel command to delete a test account.
________________________________________________________________________________
SCENARIO
You will need to associate several user accounts together into groups to make IT management at
Develetech easier. You will create several groups that correspond to different departments. At some
point, you'll need to rename the Graphics group to fit the naming scheme of the other groups. In
addition, you will add users to the groups.
Part of the user/group management lifecycle dictates that you'll occasionally need to delete groups.
So, you'll finish by deleting a group, but not the users that are part of that group.
________________________________________________________________________________
5. Verify that you deleted the group, but not its users.
a) Enter cat /etc/group to view the existing groups.
b) Confirm that the SalesDept group has been deleted.
c) Enter cat /etc/passwd to view the existing users.
d) Confirm that deleting the SalesDept group did not delete the cmason user account, even
though it was a member of that group.
SCENARIO
There are several ways a user can gather information about their own account and group
memberships. In addition, there are multiple ways of identifying what users might currently be
logged on the system. You will explore these methods to ensure you can answer questions the users
you support might have. The Develetech security policy requires that a log file of user logins be kept
in case of an audit or security incident.
________________________________________________________________________________
3. Check for information about users that are or have been logged in to the system.
a) Enter who to see what users are currently logged in to the system.
b) Enter w to see what users are currently logged in.
c) Compare who and w for details, and then observe the idle time information.
d) Enter last to see a record of recent logins to the system.
SCENARIO
You're concerned that a change to Linux systems may be difficult for users. You need to identify
what files can be used to make the user command-line environments customized and consistent. In
addition, you need to place a copy of the Develetech policies in each new user's home directory for
reference.
________________________________________________________________________________
3. Add a file to the /etc/skel directory, create a new user, and then verify that the new file was
copied to the new user's home directory.
a) Enter ls -a /etc/skel to view the files currently in this directory.
b) Enter sudo touch /etc/skel/policies.txt to create a file in the directory.
c) Enter sudo useradd jrobinson to create a new user account for Jerry Robinson.
d) Enter sudo ls -a /home/jrobinson and note the presence of the policies.txt file.
This file was copied as part of the useradd tool.
SCENARIO
You're concerned about how to protect files and directories on a Linux server. You will interpret the
existing permissions of a few files, and then configure permissions for the file owner, the group, and
all others for files and directories.
________________________________________________________________________________
2. Create a test directory and file you can configure the permissions for.
a) Enter mkdir permissions-demo to create a directory in your home directory.
b) Enter cd permissions-demo to move to that directory.
c) Enter mkdir DirA to create a permissions demonstration directory.
d) Enter touch file1 to create a permissions demonstration file.
e) Enter ls -l to view the current permissions on both objects.
3. Configure permissions for the test directory and file using absolute mode.
a) Enter chmod 755 DirA to set permissions on the directory.
b) Enter ls -l to see how the permissions have changed on the directory.
c) Enter chmod 660 file1 to set permissions on the file.
d) Enter ls -l to see how the permissions have changed on the file.
e) Enter chmod 750 DirA to set different permissions on the directory.
f) Enter ls -l to see how the permissions have changed on the directory.
g) Enter chmod 744 file1
h) Enter ls -l and note the permissions changes.
4. Configure permissions for the test directory and file using symbolic mode.
a) Enter chmod o+r DirA to set permissions on the directory.
b) Enter ls -l to see how the permissions have changed on the directory.
c) Enter chmod go+rw file1 to set different permissions on the file.
d) Enter ls -l to see how the permissions have changed on the file.
e) Enter chmod go-rwx DirA
SCENARIO
One of the Develetech employees, Chris Mason, wants to create files and directories with non-
default permissions so he can share them more easily with a co-worker. Since the requested change
does not violate the Develetech security policy, it has been approved. You will implement the
change for Chris.
________________________________________________________________________________
1. View the current default permissions settings for users that create new files and directories.
a) Enter umask
b) Verify that the default mask is 0002
For standard users, no advanced permissions are set by default (the first 0), owner and group
permissions aren't masked, and other user permissions are masked by 2
SCENARIO
You will create a Graphics department directory where department members can store content.
You will investigate default ownership and group associations, and then create the /Graphics
directory. You will configure ownership and group associations of the directory and files.
________________________________________________________________________________
1. View the current ownership and group associations for files and directories.
a) Enter ls -l /var/log/cron to view ownership and group details about this log file.
The root user is the owner, and the root group is the group.
b) Enter ls -l /etc/ssh/sshd_config to view ownership and group details about this
configuration file.
The root user is the owner, and the root group is the group.
c) Enter sudo ls -l /home/cmason to view ownership and group details about the contents of
a user's home directory.
The cmason user is the owner, and the cmason group is the group.
2. Create a directory and populate the directory with files, then manage the ownership values.
a) Enter sudo mkdir /Graphics to create a directory at the root of the file system.
b) Enter sudo touch /Graphics/file1 to create content.
c) Repeat this command with file2 and file3 to create additional empty files inside the
directory.
d) Enter ls -l /Graphics to view the ownership information.
The owner is the creator; in this case that is the root account, due to the use of the sudo
command.
e) Enter sudo chmod -R 774 /Graphics to set permissions on the /Graphics directory and its
contents.
f) Enter sudo ls -l /Graphics to view the new permissions.
3. Change the owner and group values of the /Graphics directory and its contents.
a) Enter sudo chown -R :GraphicsDept /Graphics to set the group association as GraphicsDept
b) Enter sudo ls -ld /Graphics to view the changes.
c) Enter sudo chown rstanley /Graphics/file2 to change the ownership of file2 to Rose Stanley.
d) Enter sudo ls -l /Graphics to confirm rstanley is now the owner of file2
SCENARIO
Some users have noted that the group associations for /Graphics are not applied to files created in
the directory. One user also complained that another user accidentally deleted one of her files. You
are asked to correct these concerns.
________________________________________________________________________________
1. Use SGID to automatically set group associations for newly created files in the /Graphics
directory.
a) Enter ls -ld /Graphics to see the default permissions on the / Graphics directory.
b) Enter sudo chmod g+s /Graphics to set the SGID on /Graphics so that newly created files
will get the group association.
c) Enter ls -ld /Graphics to view the new permissions.
2. Use the sticky bit to better protect files from deletion by anyone but their owner.
a) Enter sudo chmod +t /Graphics to configure the sticky bit on the /Graphics directory.
b) Enter su - jrobinson and enter Pa22w0rd to switch to Jerry Robinson's credentials.
c) Enter cd /Graphics to move to the /Graphics directory.
d) Enter rm file4 to attempt to delete the file owned by rstanley.
Note that you receive an "Operation not permitted" response. If this were a permissions
issue, you would receive an "access denied" response instead. Even though jrobinson is a
member of the GraphicsDept group, and that group has the permissions to delete a file in
this directory, the sticky bit is preventing file deletion from a non-owner.
e) Enter exit to return to the student## login.
SCENARIO
You have written a README text file to be stored in the /Graphics directory to help guide users on
the proper use of the content. You want to ensure that no one, not even the root user, can
accidentally delete the file. You will use the immutable attribute to accomplish this task.
________________________________________________________________________________
d) Enter sudo chattr +i /Graphics/README to set the immutable attribute on the README file.
e) Enter sudo ls -l /Graphics to view the current permissions and verify that they haven't
changed.
f) Enter sudo lsattr /Graphics/README to confirm the immutable attribute is set.
SCENARIO
The Graphics department has requested that the Marketing department be given read- only access
to the /Graphics directory. With standard permissions, only one group association can exist. You
will use access control lists (ACLs) to ensure that both the Graphics and Marketing departments
have access.
________________________________________________________________________________
Note: You can ignore the "Operation not permitted" warning about the README file; the ACL
settings will still apply to all other objects.
c) Enter sudo getfacl /Graphics to view the new level of access for the MarketingDept.
SCENARIO
Develetech is concerned about losing data in the event of storage drive corruption. You'll create a
couple of partitions where the team can store backups for the time being. In the event that the main
storage partition fails, these backups may remain unaffected and can be used for recovery.
So, you'll create two new partitions:
• A partition that will hold system data in an XFS file system.
• A partition that will hold critical business files and other user data in an ext4 file system.
You'll just create the partitions for now; you'll make them available for use later.
________________________________________________________________________________
Note: This associates the partition with the ext4 file system type; it doesn't actually format
the partition with an ext4 file system.
f) Examine the list of partitions you just printed and identify the End value for the last partition
(i.e., the XFS partition you created with fdisk).
g) Enter this value at the Start? prompt.
For example, if the end value is 121GB, then enter 121GB at the prompt.
h) At the End? prompt, add 8 GB to the start value and enter that.
For example, if the end value is 121GB, then you'd enter 129GB at the prompt.
i) Enter print and verify that both of your new partitions appear.
j) Write down the partition number of the partition you just created: _________________
k) Enter q to quit GNU Parted.
SCENARIO
The two backup partitions you created are acceptable, but you know there are more efficient ways
of managing separate storage devices. So, you've decided to consolidate the space in both of these
partitions to create a physical volume using the Logical Volume Manager (LVM). You'll create a single
volume group for backups that extends across these physical volumes. Then, you'll create logical
volumes for both system files and business data files.
As you create these volumes, a colleague tells you that the backup system will need to keep its own
set of logs that other members of the team can audit to ensure the backup process is running as
expected. He suggests creating another partition for these log files, with the understanding that the
size of this partition (and of the other partitions) might need to change over time. You offer to create
a logical volume instead, explaining that it'll be much easier to manage than a physical partition. He
agrees, so you'll get to work.
________________________________________________________________________________
2. Scan the system for physical volumes, volume groups, and logical volumes.
a) Enter sudo pvscan
b) Verify that at least one physical device is supporting the logical volumes.
c) Enter sudo pvdisplay to see more details about the physical volume.
The physical volume has a name in the format /dev/sda# as well as a volume group name
(centos) and size.
d) Enter sudo vgscan and verify that the centos volume group was found.
e) Enter sudo vgdisplay centos to see more information about this volume group.
f) Enter sudo lvscan and verify that the three CentOS logical volumes were identified.
g) Enter sudo lvdisplay /dev/centos/home to see more informationabout this particular logical
volume.
3. Create physical volumes from the backup partitions you created earlier.
a) Enter sudo pvcreate /dev/sda# /dev/sda# where # corresponds to each new partition you
created previously.
For example: sudo pvcreate /dev/sda4 /dev/sda5
This creates a physical volume for each partition.
b) Enter sudo vgdisplay backup and verify that you can see details about your new volume
group.
The total size of the group should be around 11 GB.
6. Extend the data backup volume and reduce the log volume.
a) Enter sudo lvextend -L5G /dev/backup/databk
This extends the databk volume from 2 GB to 5 GB in size.
d) Enter sudo vgdisplay backup and verify that the volume group has approximately 4 GB of
free space left.
Note: It's a good idea to leave free space in a volume group in case you later need to extend
a volume.
SCENARIO
Your volumes are all in place, but they aren't usable yet. You need to mount them first so that users
and applications can access their file systems. You decide to mount each of the three volumes in the
/backup directory, like this:
• /backup/sys/
• /backup/data/
• /backup/log/
In addition, these volumes need to be mounted automatically in case the system needs to reboot.
________________________________________________________________________________
3. Unmount a volume.
a) Enter sudo umount /backup/log to unmount the volume.
b) Enter mount and verify that the log volume is no longer mounted.
In this state, the volume is not currently usable. You may need to unmount a volume/
partition if you'd like to move its mount point. Also, some operations require the file system
to be unmounted before they can work with it.
f) Press Esc, then enter :wq to save the file and quit.
g) Enter sudo mount -a and verify that there are no errors.
This tests the fstab file to ensure it can mount all of the volumes that are listed in it. A
misconfigured fstab file may prevent the system from booting.
SCENARIO
So far, your new volumes have been working great. However, because backups are critical to the
business, you want to perform scheduled maintenance on each file system to spot any errors that
could corrupt data or make it inaccessible.
Also, as expected, the scope of your backup operations has changed, and it's become necessary to
expand the size of your data backup and log backup volumes to accommodate these changes. You'll
need to ensure that you resize their file systems as well, or users and apps won't be able to avail
themselves of the newly added space.
________________________________________________________________________________
2. Examine the tree structure. What can you identify about your storage devices?
Answers may vary depending on the underlying hardware, but generally, the system
reserves sda1 and sda2 as boot file systems. The sda3 device is typically a logical volume
group created by the system to house the root file system, the home file system, and swap
space. Below that should be the two physical volumes that you created, and under each
should be one or more logical volumes. Some of the logical volumes might extend across
both physical volumes.
e) Verify that the file system was resized, and that there are more total blocks than before.
f) Enter sudo mount /dev/backup/databk /backup/datato remount the ext4 file system.
SCENARIO
You need to become more familiar with the structure and design of a typical Linux file system from
a user perspective. That way, you'll be able to easily navigate the file system and find the data and
system files that you're looking for at any given time. You'll walk through several of the main
directories that were created during installation.
________________________________________________________________________________
3. Why was no file or directory found, when you were just in a directory with this name?
This is because you referenced a relative path, which means Linux tried to open a directory
called etc within /etc/ssh
SCENARIO
Lately, users have been complaining about poor performance and latency when they read files or
write files to storage. Some users have also run into errors that say the storage device is full when
they attempt to write to it. You spoke to some of these users to get more information, and a few of
them mentioned that they were trying to back up data from their home directories when they ran
into these errors. Using this information, you'll attempt to diagnose the storage issues on the Linux
system.
________________________________________________________________________________
b) Enter cat /sys/block/sda/queue/scheduler and verify that your scheduler was set.
The scheduler enclosed in brackets is the active one
SCENARIO
After identifying excessive storage consumption on the data backup volume, you realize that most
of these files were created by the ariley user. You decide to limit storage space usage for ariley on
the data backup volume according to the following details:
• Block soft limit=10000
• Block hard limit=15000
• Inode soft limit=500
• Inode hard limit=700
These limitations will help prevent the performance and space consumption issues that users were
experiencing.
________________________________________________________________________________
2. Configure the user quotas for the data backup file system.
a) Enter sudo quotacheck -cugm /backup/data
This creates the necessary quota files for the file system.
b) Enter sudo quotaon -a to turn on quotas for the file system.
3. Limit the ability for ariley to create data on the backup file system.
a) Enter sudo edquota -u ariley
b) Edit the configuration file to specify the following limitations:
/dev/mapper/backup-databk 0 10000 15000 0 500 700
7. The user has reached the soft limit for storage blocks. What does this mean as far as the
user's ability to write data to this file system?
The user will be able to continue to exceed this soft limit for a default of seven days. If they
go below the soft limit, the timer will reset. If they don't go below the soft limit within the
grace period, or if they exceed the hard limit within the grace period, then they will be unable
to write to the file system.
SCENARIO
As one of the Linux server administrators, you've been asked to start a list of software that is
installed or should be installed on the system. So, you'll create a text file and begin entering the
names of software packages into it. You'll then save your work and pick up with the file later.
________________________________________________________________________________
DATA FILE
/opt/linuxplus/managing_files_and_directories/software_list.txt
SCENARIO
A colleague has taken your initial software list file and started filling it out. After he's done, you look
it over to see if there are any mistakes that need correcting. You'll edit this file in both Vim and GNU
nano to become more familiar with both text editors.
________________________________________________________________________________
Note: Remember, you can use tab completion to speed up the process.
3. Use the search functionality to find and fix the other instance of the spelling error.
a) Enter /Frie to search for the next occurrence of the misspelled name.
b) Correct the name so that it says "Firefox".
Note: You can also use the spacebar for more precise alignment.
d) Type 9.0.12
e) Place the cursor under the "Installed?" column and type N
f) Type N under the "Configured?" column.
SCENARIO
One of your duties as a Linux administrator is to ensure your system logs are functioning as
expected. These logs are crucial to diagnosing issues and identifying other unwanted behavior. So,
to start, you'll search for where the log files are stored on your system. Then, you'll begin to search
for logs that meet specific size requirements and have been recently updated. That way you'll be
able to confirm which logs are continuously recording a significant amount of information, as
expected.
________________________________________________________________________________
3. Search for log files that have been updated within the last 30 minutes.
a) Enter sudo find /var/log -type f -mmin -30
b) Verify that one of the files in the results has a timestamp within the last 30 minutes.
4. Search for log files that are either empty or above 100 KB, and have been updated in the last
30 minutes.
a) Enter sudo find /var/log -type f -size 0 -or -size +100k -mmin -30
b) Verify that these conditions are accurate for at least one of the files.
5. What are some advantages of using the find command over using the locate command?
The locate command requires that a database be updated in order to perform accurate
searches, whereas find does not. Also, locate cannot filter its search by specific directories,
whereas find can. However, locate may be able to perform searches more quickly in certain
cases.
SCENARIO
Another one of your duties is, naturally, to review the system's log files. But before you dive into log
analysis, you need to determine the best way to display text files for reading. So, you'll use
commands like cat and less to see where each one can come in handy.
________________________________________________________________________________
c) Press n to view the next instance of this text string in the file.
d) Press N (note the capitalization) to navigate to the previous instance of the search term in
the file.
e) Press q to quit reading the file.
4. Why might printing only the first or last few lines be preferable to reading the entire file?
Answers may vary, as it depends on the purpose and format of the text file. For logs, reading
the last 10 lines is a much quicker way to see the latest events on a system than using less
would be. Printing the first 10 lines might be useful in situations where entries are repeated
or otherwise superfluous, and you only need to see a few examples to grasp the idea.
DATA FILE
All files in: /opt/linuxplus/managing_files_and_directories/aups
SCENARIO
You've been asked to move some corporate policy documents from the HR lead's workstation to a
Linux server. The policies should be more centrally available and not dependent on one particular
person's system. The HR lead admits that she didn't do a great job organizing the policy documents,
as several older versions of acceptable use policies (AUPs) are mixed in with more current, active
versions, and the old policies were written before she implemented a consistent naming
convention. All of the documents are in a single directory named aups.
First, you'll need to copy the documents to your home directory as a temporary staging area. You'll
then organize these policy documents by retaining only the most recent ones and deleting older
ones that no longer apply. You've also been told that more types of policies will need to be located
on the server, other than AUPs. So, you'll effectively rename the aups folder to the more general
policies and create some placeholder files. Later, when you receive more policies to add, you'll be
able to deploy the directory where other authorized users can reach it.
________________________________________________________________________________
2. Create a new directory and move the most recent policy files into it.
a) Enter mkdir ../policies to create a new directory.
b) Enter mv aup_v1.txt ../policies
c) Enter mv aup_v2.txt ../policies
d) Enter ls -l and verify that these two files are no longer in this directory.
3. Verify that the recent policies were moved to the new folder.
a) Enter cd ../policies
b) Enter ls -l and verify that the two recent files are in this directory.
5. Delete the aups folder and its contents as they're no longer needed.
a) Enter rmdir ../aups
b) Verify that you cannot remove this object because it is a directory.
You need to specify the -R (recursivoption with rm in order to delete non-empty directories.
c) Enter rm -R ../aups
d) Enter ls .. and verify that the aups directory is gone, as are the old policy files.
SCENARIO
Now that the software list and policy documents are all set and in the right locations, you can begin
to analyze them more closely. In particular, you want to sort the software list so you can more
quickly identify what software packages still need to be installed and/or configured. Likewise, you
want to ensure that you know exactly what was changed from the first version of the AUP to the
second version, so you don't have to read the entire thing from the beginning.
You also want to switch gears to your log analysis duties. You want to identify instances where users
enter an incorrect password and fail to log in. This could point to users that are trying to access
resources they are not authorized for. However, the authentication log can be very large, so you'll
need to process it in order to extract only the relevant information.
________________________________________________________________________________
1. Sort the software list file by name, then by which packages need to be installed and/or
configured.
a) Enter cd ~ to return to your home directory.
b) Enter cat software_list.txt to review the column structure of this file.
c) Enter sort -k1 software_list.txt
d) Verify that the list was sorted by the first column, which is the name of each software
package.
However, the sort operation was not perfect, as the column headers were included. There
are several ways to stop this from happening, one of which you'll perform in a later topic.
e) Enter sort -k3 software_list.txt to sort by the "Installed?" column.
f) Sort by the "Configured?" column.
• In other words, the HR lead added this entire new section to version 2 of the policy.
• 35a44 means that after line 35 in the first file, line 44 from the second file needs to be
added in order for the text to be the same.
• In other words, the HR lead added an entry to the revision history explaining her changes.
SCENARIO
You've decided to start organizing your backup directory, particularly with regard to log files. You
want to create several subdirectories, each one a category that can pertain to the backed up logs.
For example, you want to organize logs by type (e.g., authentication logs vs. app logs vs. kernel logs)
and the year that they were generated. However, most logs can apply to multiple categories. Rather
than have two or more distinct copies of each log, you decide to link these files together so that
they're easier to manage.
You also want to be able to quickly access log backups from your home directory. So, you'll create a
link in your home directory to a log in the backup directory.
________________________________________________________________________________
1. Create new log backup directories and move the authentication log to one of them.
a) Enter mkdir /backup/log/auth /backup/log/<year> where <year> refers to the current
year.
b) Enter sudo cp /var/log/secure /backup/log/auth/secure
c) Enter cd /backup/log
Note: You can run diff auth/secure <year>/secure if you want to be sure.
3. Make a change in one file and see it reflected in the hard link file.
a) Enter sudo nano auth/secure
b) Press Enter to start a new line at the top.
c) Type **BEGIN LOG ##-####** where ##-#### is the current month and year.
For example: **BEGIN LOG 01-2019**
4. Remove one file and verify that the hard link file is still intact.
a) Enter sudo rm auth/secure
b) Enter sudo cat <year>/secure and verify that the hard link file's contents are still intact.
5. Attempt to create a link from your home directory to a log file in the backup directory.
a) Enter cd ~ to return to your home directory.
b) Enter sudo ln /backup/log/<year>/secure auth-log
c) Verify that the operation failed.
6. Why did the system fail to create the link? What can you do to still create a link?
You cannot create hard links across different file systems, and the home directory and the
backup log directory are on different file systems. To get around this, you must create a soft
(symbolic) link.
8. Delete the original log file and verify that the symbolic link was affected.
a) Enter sudo rm /backup/log/<year>/secure
b) Enter sudo cat auth-log and verify that no such file exists.
c) Enter ls -l and verify that the file is a broken link.
The red text pointing to text with a black background indicates that the link is broken.
d) Enter rm auth-log to delete the symbolic link.
DATA FILE
/opt/linuxplus/managing_files_and_directories/laptop_inv.txt
SCENARIO
In the past, the IT team has kept an inventory of all laptops issued to employees. As part of the new
roll-out, you'll need to copy this information to a document that will be stored on a Linux server.
The source information isn't formatted very well, and isn't in any kind of useful order. So, you decide
to create a new file from scratch. Afterward, you realize that the person who recorded the
information made a mistake with the format of certain serial numbers. Instead of editing the file to
replace every mistake individually, you'll leverage input and output redirection to fix the mistakes.
Then, you'll output a sorted version that will be more useful for reference.
You also want to regularly check the contents of the backup directory and place the results in a
continually updated file. You want to be able to see the results in real-time at the CLI as well, so
you'll use the tee command to accomplish both.
Lastly, you'll use piping with grep to further hone your log analysis skills
________________________________________________________________________________
1. Use output redirection to start adding text to the laptop inventory file.
a) Enter touch laptop_inv.txt to create a blank file.
b) Enter echo "User Make Serial No." > laptop_inv.txt
c) Enter cat laptop_inv.txt and verify that the text output to the file.
Note: Remember, you can press the Up Arrow to return to a command you previously
entered.
e) Verify that the file has both the header and the first row.
3. Use input redirection to replace all instances of a mistyped character in the file.
a) Enter the following:
cp /opt/linuxplus/managing_files_and_directories/ laptop_inv.txt laptop_inv.txt
This will update your copy with a filled-in one.
b) Examine the file and verify that the Asus serial numbers incorrectly start with the capital
letter "S".
c) Enter tr S 5 < laptop_inv.txt
d) Verify that the instances of "S" were replaced with "5" and that the file was printed to the
CLI.
4. Use both input and output redirection at the same time to create a new file with the
corrections.
a) Enter tr S 5 < laptop_inv.txt > laptop_inv_fix.txt
b) Examine the corrected file and verify that the appropriate correction was made.
6. Use the tee command to redirect output to both the CLI and a file at the same time.
a) Enter sudo ls -lR /backup > backup_report
b) Verify that ls didn't print its results to the CLI.
c) Enter sudo ls -lR /backup | tee backup_report
d) Verify that ls did print its results to the CLI.
This is because piping the ls command to tee instead of doing a stdout redirect ensures that
the results will appear at both the CLI and the specified file.
e) Examine the backup_report file and verify that it also lists directory information.
SCENARIO
As a system administrator, you may need to troubleshoot issues related to the kernel. So, you want
to explore kernel concepts to refresh your knowledge.
________________________________________________________________________________
2. What is the base version of your currently running kernel according to the uname command?
o 2.4
o 2.6
o 3.4
o 3.10
o 4.18
3. True or false? According to the uname command, you are running a 32-bit hardware
platform.
o True
o False
5. What are the major functions performed by the kernel? (Choose two.)
Kernel initialization
Process management
Memory management
Module installation
Dependency management
6. Which of the following accurately describe the user space? (Choose two.)
It is the area of the memory where the kernel executes its services.
It is the area of memory in which most high-level software runs.
It is the part of the system that only logged in users can access.
It is the area of memory in which background processes and low-level system libraries run.
8. True or false? The Linux kernel is modular, enabling users to extend its functionality.
o True
o False
SCENARIO
You want to be able to wirelessly transfer files from the Linux server to your mobile device. So, you
purchase a USB Bluetooth adapter and plug it into an available port on the server. However, you
can't get the adapter to work properly. After examining the system, you discover that the driver for
USB Bluetooth is not available. So, you'll inspect the kernel and see if you can identify and load the
module that enables this functionality.
________________________________________________________________________________
Note: Remember to use tab completion to fill the kernel version automatically.
3. Do any of these look like they could be a driver for a USB device that can send and receive
Bluetooth signals?
Answers may vary, but btusb.ko.xz is the most likely candidate.
7. Notice that there are other modules that begin with bt, as well as a module called
bluetooth. Why were these added to the kernel as well?
These are modules that btusb depends on in order to function. The modprobe command
automatically installs dependent modules when necessary.
SCENARIO
Now that you installed the USB Bluetooth module, you want to make sure it was successfully loaded
by the kernel and that there are no errors. You also want to identify your kernel version details in
case you need to reference it during troubleshooting.
________________________________________________________________________________
1. Enter cat /proc/version and use the result to answer the following questions.
When was the kernel last compiled?
Answers may vary, but the version used to develop this course was compiled on April 20 of
2018.
What version of the GCC is your kernel running?
Answers may vary depending on when the kernel was compiled. For the kernel version used
to develop this course, the GCC version is 4.8.5.
Why might this information be useful?
Answers may vary, but validating the kernel version and related information can help you
diagnose issues that apply to specific versions, such as incompatible software.
4. Search the kernel message buffer for evidence of USB drivers being loaded.
a) Enter dmesg -H | grep usb
b) Examine the results.
The kernel records when USB storage devices are found and when drivers are registered. It
also identifies when input devices that use USB are found—like a mouse, keyboard, webcam,
etc.
c) Enter dmesg -H | grep btusb
d) Verify that the kernel is reporting that a new interface driver was registered for the btusb
module you installed earlier.
SCENARIO
As part of your server infrastructure, you plan on having some systems boot from an NFS share. The
kernel in the deployed systems doesn't have an NFS module. Without this, your systems cannot
mount an NFS share as the root file system. So, you need to create a new initrd image so that the
kernel can successfully mount the share. First, however, you'll establish a baseline image that other
images can build off of.
________________________________________________________________________________
SCENARIO
Some of your fellow administrators are claiming that their Linux servers aren't booting properly.
You are assigned to the task of troubleshooting these issues. You find that someone has modified
the settings in the boot loader because there is no password protection. After correcting the boot
configuration, you decide to protect GRUB 2 with a password so that only authorized users can
modify it.
________________________________________________________________________________
Caution: Input your user name and password very carefully, as you will be unable to edit any
mistakes.
SCENARIO
One of your colleagues is located remotely—in London, England. Just like you, he needs to be able
to log in to Develetech's Linux servers in order to administrate them. The server he needs to
remotely administrate is located in the US, even though it primarily services users in Great Britain.
So, you'll set this server to use the time zone in London, as well as change the language and keyboard
layout settings to those of Great Britain. This will make it easier for your English colleague to work
within the environment and for the server to operate within the correct time zone.
________________________________________________________________________________
d) Verify that the universal time is either the same as the local time or is one hour behind,
depending on the time of year.
The universal time is synonymous with GMT/UTC and is used as a global reference point.
e) Examine the RTC time.
This is the hardware clock, and it is set by the OS. Many Linux distros set this to UTC by
default, including CentOS. You'll leave this as-is.
f) Enter date to confirm the date and time on the system.
Caution: Take note of these values if your locale and keyboard layout are not US. You will
need to revert to these values at the end of the activity.
Note: Press the Up Arrow until you retrieve the command you used to set the locale to Great
Britain. Then you can just replace the text.
Caution: If your original language and keyboard layout are something other than US, you will
need to enter your original values instead.
SCENARIO
The CLI has been adequate so far, but many of your colleagues would be more comfortable working
in a visual environment. A GUI is also necessary for easily browsing the web and viewing media like
images and video. Most of your colleagues prefer to work with GNOME, the default desktop
environment, whereas others prefer a customized version of KDE. So, you'll start by configuring
KDE's layout options to align with those users' preferences. Then, you'll get accustomed to
navigating through GNOME, the environment you yourself will be using. You also need to configure
some accessibility options in GNOME for users who have visual and manual dexterity impairments.
________________________________________________________________________________
c) Select student##.
d) To the left of the Sign In button, select the Settings gear icon.
e) Select KDE Plasma Workspace.
f) Enter your password and select Sign In.
e) Select OK to apply the settings and close the Desktop Settings - Plasma Desktop Shell
window.
f) Examine the new layout of the desktop environment.
3. Switch to GNOME.
a) From the top-right of the desktop, select the Desktop menu, then select Leave.
b) Select Logout.
c) Select student##.
d) To the left of the Sign In button, select the Settings icon.
e) Select GNOME Classic.
f) Sign in using your password.
i) Examine the desktop and note that GNOME has a different look and feel than KDE.
6. Enable accessibility settings in GNOME for users with visual and manual dexterity
impairments.
a) Select Applications→System Tools→Settings.
b) From the navigation pane on the left, select Universal Access.
c) In the Seeing section, slide the High Contrast slider to On.
d) In the Typing section, slide the Screen Keyboard slider to On.
e) Close the Settings window.
SCENARIO
As a Linux administrator at Develetech, you know that you will be implementing, managing, and
reconfiguring different services. You'll be leveraging systemd, and in particular, the systemctl
command and its associated subcommands, to manage these services. You decide to start by
switching targets from CLI to GUI, and then making the default target GUI so that users will always
boot into that environment by default. Then, you'll practice managing the SSH and firewall services
by putting them through the service management lifecycle of starting, stopping, enabling, and
disabling them.
________________________________________________________________________________
1. Verify that your system is using systemd and not the older SysVinit method.
a) In the terminal window, enter ps -e | grep -i init to check for the init process.
b) Verify that the init process was not found.
c) Enter ps -e | grep -i systemd to check for the systemd process.
d) Verify that the systemd process was found and has a process ID of 1
2. View the target files that specify the services that will start when the system starts.
a) Enter cat /usr/lib/systemd/system/multi-user.target
Observe that the multi-user.target requires the basic.target— i.e., the target files build upon
each other.
b) Enter cat /usr/lib/systemd/system/graphical.target
Observe that the graphical.target requires the multi-user.target—this further illustrates
how the target files build on each other. In addition, the graphical.target calls or "wants"
the display-manager.service, which initiates the GUI.
c) Enter systemctl --type=service to view the current target's services.
d) Press q when you're finished.
3. Switch between the CLI target and the GUI target, then set the GUI target as the default.
a) Enter sudo systemctl isolate multi-user.target to switch back to the command-line
interface.
b) Sign in as student##
c) Enter sudo systemctl isolate graphical.target to switch to the graphical user interface.
d) Sign in as student## and open a terminal.
e) Enter sudo systemctl set-default graphical.target to set the GUI as the default environment.
Caution: Be sure to add a space after the command and before pressing Tab.
b) Note the stop, start, restart, status, enable, and disable subcommands in particular.
e) Enter sudo systemctl start sshd.service to start the sshd service again, then check its status
to ensure it is running.
SCENARIO
Some users have complained that processes on the Linux server are taking longer than normal to
complete. You discover several processes that are not needed are still running and were never
successfully terminated. You need to manage the system processes and the processes issued by
other users. In addition, you'll see if there are any problem processes that are consuming too many
resources or are causing delays in the boot process.
________________________________________________________________________________
1. View the current running processes and all other running processes.
a) Enter ps to list only the processes running on the current terminal.
b) Verify that only the processes started by your account are listed.
c) Enter ps -e to list all the processes running on the system.
d) Verify that more processes are listed as compared to the output of the standard ps
command.
2. Discover the process ID number of a process for which you know the name.
a) Enter pgrep sshd
b) Note the process ID number of the sshd service.
6. Discover what files are open, and which processes opened them.
a) Enter lsof
b) Enter lsof -u student## to see files opened by a specific user.
a) Enter systemd-analyze
The results of the systemd-analyze command break the startup process into three parts:
how long it took the kernel to start, how long it took the initrd image to load, and how long
user startup applications and services took to start. The command also shows the total
amount of time the startup took. This information can be used in troubleshooting long
startup times.
b) Enter systemd-analyze blame to see which processes take the longest to start during boot.
c) Press q.
SCENARIO
You want to back up the local copy of the /etc/ configuration directory. You expect the copying
process to be time-consuming and to continue after you log out of your system. You decide to
increase the priority of the process to ensure that it is completed on time.
________________________________________________________________________________
SCENARIO
You want to identify some basic tools to help manage system components. Specifically, you'll review
processor and memory usage to see if the results match expected performance.
________________________________________________________________________________
SCENARIO
One of your colleagues uses a Linux system to prep OS installation media on a USB thumb drive.
However, every time she plugs her USB drive into the system, it automatically assigns the drive a
non-descriptive name like /dev/sdb. She'd like to be able to reference the drive with a more helpful
name every time she plugs it in. So, you'll use udev to create a symbolic link to the drive based on
its unique attributes.
________________________________________________________________________________
2. Create a udev rule that will automatically link a custom device name to the USB drive when
it's plugged in.
a) Right-click within the terminal and select Open Terminal to open a new window.
b) In the new terminal window, change to the /etc/udev/rules.d directory.
c) Using sudo, create a text file named 10-local.rules with the text editor of your choice.
d) In this text file, enter the following all on one line:
KERNEL=="<device name>", ATTRS{serial}=="<value>",
ATTRS{idVendor}=="<value>", ATTRS{idProduct}=="<value>",
SYMLINK+="install"
Fill in the replacement values with the values identified in your other terminal. Make sure
the values are from the same parent device that you identified as having the serial number.
Also, <device name> should be in the format sdb and not /dev/sdb
e) Save and close the file.
SCENARIO
HR wants to distribute the acceptable use policy (AUP) to employees at Develetech in both hardcopy
and electronic form. Right now, you don't have an actual printer connected to your Linux system,
but you can still print the AUP text file to a PDF, which is more suitable than a raw text file for
distribution purposes. Before you can create the PDF, you'll need to set up a virtual printer.
________________________________________________________________________________
Note: You may need to issue this command twice in order to successfully download the
package.
SCENARIO
As part of your routine system administration tasks, you need to track the devices used on all the
computers on the network and maintain a list of hardware resources that are in use.
SCENARIO
You need to ensure the system's hostname and IP address configuration is correct. You also need
to be able to configure network settings whether or not a GUI is installed. You will configure the
system with both a static IP address and a dynamic IP address.
________________________________________________________________________________
Use the NIC <device ID> from the output of the previous step. For example, the device ID
value might be enp0s3
Note: One of the first steps in networking troubleshooting is to verify the current IP address
configuration. Therefore, the ip command will be essential to your network troubleshooting
process.
Note: Your instructor may provide you with different IP addressing information.
Note: Use the Tab key and the arrow keys to navigate text-based user interfaces. Use the
Spacebar to check/uncheck settings. Use the Enter key to accept a configuration.
e) Press the Tab key three times to move to the IPv4 CONFIGURATION line.
That line currently displays <Manual>.
f) Press Enter and select Automatic from the menu.
g) Press the Tab key multiple times until you reach the bottom of the interface and <OK> is
highlighted.
h) Press Enter to save your changes to the network configuration.
i) Use the Tab key to highlight <Back> and then press Enter.
j) In the NetworkManager TUI interface, use the Down Arrow key to highlight Quit and then
press Enter.
k) Enter ip addr show <device ID> and notice that the old statically assigned IP address is still
in place.
This is because you need to restart the network service for changes to take effect.
l) Enter sudo systemctl restart network
m) Enter ip addr show <device ID> and notice a new IP address is configured, leased from a
DHCP server.
Note: The NIC details may still show the static IP address.
Note: Your instructor may provide you with different IP addressing information.
SCENARIO
Now that you've configured a NIC, you need to verify that those configurations are active and
accurate. So, you'll use ethtool and the device's configuration file to confirm the networking details.
________________________________________________________________________________
DATA FILE
/opt/linuxplus/managing_networking/yum-script.sh
/opt/linuxplus/managing_networking/CentOS-7-x86_64-DVD-1804.iso
/opt/linuxplus/managing_networking/ubuntu-vm.qcow2
SCENARIO
One of the developers at Develetech has asked for your help. She needs Linux test environments to
test that her application functions as designed. She'd like to manage the environments herself and
be able to revert back to their original configuration for each test. You will install a KVM
virtualization solution for her.
________________________________________________________________________________
Note: If you receive an error that there is no space left on the device, reboot CentOS and try
again.
d) From the bottom-left corner, select the Show Applications button need to scroll the VM
window down to locate this button.
Note: If at any time you're prompted by the Software Updater dialog box, select Remind Me
Later.
Note: You may need to issue the shut down command twice.
SCENARIO
You want to use some of the Linux network troubleshooting utilities so that you can better
understand the Develetech network environment. These will help you diagnose and solve issues
related to latency, lack of hostname resolution, inability to connect to other hosts, and more.
________________________________________________________________________________
1. View network services that are currently listening on the hosts in your network.
a) Enter ip addr to verify the system has a correct IP address configuration.
Note: When troubleshooting, an IP address that begins with 169.254 indicates the client
could not lease an IP address from a DHCP server.
b) Enter ss -l | less to see what TCP ports your system is currently listening on, then press q to
return to the prompt.
c) Enter nc localhost 21
d) You should receive a "Connection refused" error, indicating that your system is not listening
on port 21 (FTP).
e) Enter nc <partner hostname> 22 to verify that your partner's host is listening on port 22
(SSH).
f) Press Ctrl+C to disconnect.
g) You can use a tool like nc to identify network services that aren't listening on the local or
remote host.
You can use a network capture tool like tcpdump to learn more about the traffic that is
transmitted and received over your network.
f) Close the terminal window running the tcpdump capture.
DATA FILES
/Packages/ksh-20120801-137.el7.x86_64.rpm
/Packages/vsftpd-3.0.2-22.el7.x86_64.rpm
SCENARIO
One of the other Develetech administrators has asked you to demonstrate the software
management lifecycle on a CentOS server. You will use the KornShell (ksh) as an example of how to
use the rpm command, and then the Very Secure FTP daemon (vsftpd) to demonstrate the yum
command.
________________________________________________________________________________
Note: If you include a -y option with yum, it will automatically answer yes to this prompt and
not pause the installation.
SCENARIO
Some Linux systems in Develetech run Ubuntu and other versions of Debian. Just like your Red Hat-
based systems, these need to undergo network troubleshooting from time-to-time. So, you'll
download and install the nmap package on these machines to ensure you have the right toolset for
the job. You'll use dpkg and APT.
________________________________________________________________________________
Note: If the Ubuntu VM has no Internet connectivity, you may need to restart your CentOS
host and then reload the VM.
Note: If you receive a "Could not get lock..." error, it means the APT package manager is
automatically checking for updates. You could wait a few moments or kill the process
manually.
Note: You might need to maximize the VM window or scroll to see the prompt asking you to
confirm the operation.
d) Enter apt show nmap to discover information about the nmap package.
e) Enter nmap localhost to test the utility, confirming that it executes and checks the VM's
basic network functionality.
SCENARIO
While the Linux vendors tend to provide online repositories, one of the concerns with using these
is version control of applications. Develetech has decided to manage an internal repository of
software packages, making version control much easier. You will configure a local YUM repository
on the CentOS server. You will then make a YUM repository available using Apache HTTP Server.
________________________________________________________________________________
SCENARIO
You are investigating ways of downloading software from the web. Specifically, you are considering
writing a script to automate the download process. You will use wget and curl to try the downloads
manually.
________________________________________________________________________________
Note: You will compile the Nmap utility source files in a later activity. Your current objective
is just to acquire and unpackage it.
SCENARIO
Develetech will be relying on Nmap to troubleshoot its networked systems and perform
vulnerability assessments. You know that compiling Nmap from source code enables greater
flexibility and control. You will do a basic software compile of Nmap.
________________________________________________________________________________
SCENARIO
The data you'll be backing up to your various logical volumes is sensitive in nature and should not
be readable if it were to fall into the wrong hands. To protect the confidentiality of your backed up
data, you'll encrypt the volumes that hold this data. You'll start with the databk volume. Without
the correct key (e.g., a passphrase), a user will only see the scrambled ciphertext of this volume, and
will be unable to read the plaintext data of individual files.
________________________________________________________________________________
b) Enter sudo cat /etc/crypttab and confirm that the line was added.
This file is similar to /etc/fstab and initializes encrypted storage devices at boot.
c) Using sudo, open the /etc/fstab file in your text editor of choice.
d) Edit the line that mounts the /dev/backup/databk volume to say the following:
/dev/mapper/databk /backup/data ext4 nofail 0 0
This will mount the encrypted volume after it has been unlocked. The nofail option indicates
that the system should not report any errors if the volume is not detected.
e) Save and close the file.
Note: Encrypting a volume in this way requires physical access to the computer in order to
unlock it and complete the boot process. You won't be able to SSH into the system to unlock
it.
SCENARIO
You want to enable your fellow administrators to remotely access servers that are physically located
elsewhere. By default, the servers are already set up to accept encrypted SSH connections. Recently,
however, Develetech has been the victim of several brute force password cracking attempts.
Attackers have tried to gain remote access by running through various combinations of passwords.
To minimize the risk of these attacks, you decide to change the authentication method that
administrators will use to connect remotely. You'll have them each generate a cryptographic key
pair that they'll use to prove their identities. Anyone without the key will be denied access. You'll
also disable password authentication on the servers to mitigate brute force attacks.
________________________________________________________________________________
1. Generate a public and private key pair to use with SSH authentication.
a) Enter ssh-keygen
b) Press Enter to accept the default path in which to save the key.
c) Enter lpic-1 as the passphrase.
You don't need to protect a private key with a passphrase, but doing so adds a second factor
to the authentication process, and is recommended. The passphrase will decrypt the private
key before it is used to solve the server's encrypted challenge.
d) Enter the passphrase again.
e) Verify that the keys were generated and saved to the home directory.
f) Enter cat .ssh/id_rsa and examine the (encrypteprivate key. This is the key you'll use to
validate the SSH server's encrypted challenge.
g) Enter cat .ssh/id_rsa.pub and examine the public key.
The server needs to install this public key once. The server will use this public key to verify
the authenticity of the private key.
Caution: The student## number should be your partner's number, not yours. This is because
they don't have your specific student account on their system, so you have to use theirs.
3. Verify that your partner's public key was added to your server.
a) Wait for your partner to finish copying their key to your server.
b) Enter cat .ssh/authorized_keys and verify that your partner's key was added.
Any public keys added to this file are considered authorized and will be used in SSH
authentication. If you wanted to authenticate other users, you could have them generate a
unique key pair and then add their public key to this file as well.
4. Authenticate with your partner's SSH server using your private key.
a) Enter ssh student##@<partner IP address or hostname>
b) When prompted, type (but don't press Enter) lpic-1 as the passphrase to unlock your private
key.
c) Check the Automatically unlock this key whenever I'm logged in check box.
d) Select Unlock.
e) Verify that you are signed in to your partner's server as their student account.
Note: If you get an "Authentication failed" message, enter the ssh command again.
SCENARIO
The Apache web server you installed is serving its purpose, but the team would like to organize the
server's files in a more descriptive way than the default /var/www/ html directory. Also, the system
will eventually run multiple web apps, each in a different path. For now, you need to place all of the
web server files in a new /var/develweb directory. Even though you apply the correct standard
permissions and configure Apache to allow access, SELinux will prevent the httpd service from
reading files in this new directory. So, you'll configure SELinux as needed to make sure the web
server is operational.
________________________________________________________________________________
3. Configure Apache settings to use the new path as the document root and enable access.
a) Using sudo, open the /etc/httpd/conf/httpd.conf in the text editor of your choice.
b) Enter /DocumentRoot to search for the appropriate field.
c) Change this field to the following:
DocumentRoot "/var/develweb"
d) Below this, look for the <Directory "/var/www"> line and change it to the following:
<Directory "/var/develweb">
e) Save and quit the file.
f) Enter sudo systemctl restart httpd
g) Verify that the proposed solution involves changing the context label on the new directory
path.
The troubleshooter mentions many possible file types, but there is a way to narrow down
which one you need to use.
h) Close this dialog box.
5. Verify the required SELinux context and the current one applied to the new path.
a) At a terminal, enter ls -Z /var/www
Retrieving SELinux context information from the default document root should provide you
with what you need.
b) Verify that the "type" context for the html directory is httpd_sys_content_t
This is the context you need to apply to your new directory to allow Apache to access the
files.
c) Enter ls -aZ /var/develweb and verify that the "type" context for your new directory is var_t
This new directory inherited the default context of its container directory (/var).
SCENARIO
Your fellow network administrators have designed a DMZ in which you'll need to place several
public-facing Linux systems. For the most part, these systems function as web servers, and need to
allow users to connect using the HTTP and HTTPS protocols. The servers are also running a custom
app that the development team has programmed to accept connections on port 7743.
So, your job is to tighten the network security of the servers without denying access to the necessary
services. You'll do this by configuring the firewalld service, the default and preferred firewall service
on CentOS 7.
________________________________________________________________________________
g) Verify that you are able to make a connection, indicating that SSH traffic is allowed.
h) Enter exit to close the SSH session.
SCENARIO
You want to ensure that your system is logging only messages that are useful to you and other
analysts. So, you'll configure the local logging behavior to be more fine- tuned and less noisy. In
addition, each system should be sending its authentication logs to a remote, centralized server for
easy analysis and storage. So, you'll configure rsyslog to send these messages to a remote host over
the network.
________________________________________________________________________________
For example, the authpriv.* facility refers to private authentication messages, such as login
and logout events. The asterisk (*) indicates that all severities should be logged.
d) Verify that each line has a corresponding action in the right column.
For example, the authpriv.* facility will log its messages in the /var/log/ secure file.
6. Generate an authentication failure message and confirm it was sent to your partner's server.
a) Enter su - ariley
b) Provide an incorrect password and verify that you failed to log in as this user.
c) Wait for your partner to finish performing all of the previous steps.
d) Enter sudo tail /var/log/secure | grep ariley
e) Verify that you see an authentication failure message that was sent from your partner.
SCENARIO
Up until now, you've examined a few logs using standard tools like cat and less, and also filtered
those logs using a tool like grep. However, you can also use journalctl to more efficiently shape
those log messages in order to extract the specific information you're looking for. You'll also use last
and its associated commands to get an overview of login events, such as when a user last logged in.
________________________________________________________________________________
DATA FILES
All files in: /opt/linuxplus/securing_linux_systems/employee_data
SCENARIO
On a yearly basis, HR has been compiling information about Develetech employees and putting
them in a spreadsheet. These spreadsheets contain personal information such as names, addresses,
and phone numbers. You need to ensure that past years' reports are stored in backup should they
ever need to be retrieved in the future. Because you won't need to regularly update these files, you
decide to place them in a single archive. You also want to test the process of recovering the files
from this archive if it's ever necessary.
________________________________________________________________________________
Note: Open the Files app, then select + Other Locations, then select the encrypted volume
and input lpic-1 as the passphrase.
3. Archive the employee data files and then copy the archive to the data backup volume.
a) Enter tar -cvf employee_data.tar employee_data/*
This creates a new archive with the specified name. The asterisk (*) indicates that all files
within the employee_data directory should be added to the archive.
b) Enter ls -l and verify that the .tar file is present.
c) Enter tar -tf employee_data.tar to list the contents of the archive.
d) Enter sudo cp employee_data.tar /backup/data/employee_data.tar
e) Enter ls -l /backup/data and verify that the archive file is now on the data backup volume.
4. Restore all files from the archive, then restore a single file.
a) Enter cd /backup/data to change your current working directory.
b) Enter sudo tar -xf /backup/data/employee_data.tar
c) Enter ls -l employee_data and verify that all of the files were extracted to the directory.
d) Enter sudo rm -r employee_data to delete the directory.
e) Enter sudo tar -xf employee_data.tar employee_data/emp_2018.csv
f) Enter ls -l employee_data and verify that only the one file was extracted.
g) Enter sudo rm -r employee_data to delete the directory.
DATA FILES
All files in: /opt/linuxplus/securing_linux_systems/prototypes
SCENARIO
The Research and Development (R&D) department also has sensitive data that they need backed
up: data on product prototypes, including model numbers, pricing, and release dates. Unlike the
employee data, these files are likely to be updated regularly. So, you want to make sure the backup
copies consistently align with the source copies. You'll use rsync to synchronize both copies,
ensuring that the backup copies will only need to be updated if the source files have changed.
________________________________________________________________________________
d) Enter cat /backup/data/prototypes/swatch.csv and verify that your change was added to
the backup version of the file.
SCENARIO
As you archive more and more data, you realize that the archives take up just as much space as the
files they hold. This is a waste of space, especially if you're not working with the archives' contents
regularly. So, you'll compress the archives so that they take up significantly less space without losing
any data. You'll also try several different compression algorithms and compare their performance.
________________________________________________________________________________
1. Note the size of the employee data archive on the backup volume.
a) Enter cd /backup/data
b) Enter ls -lh and note the size of employee_data.tar that you created earlier.
c) Enter ls -lh and verify that the employee_data.tar.xz file is even smaller than the .gz file.
d) Enter sudo tar -xJf employee_data.tar.xz
The tar command can also work with .xz files through the -J option. As before, this
decompresses and unarchives the .tar archive all in one command.
e) Enter ls -l employee_data and verify that all of the files are there.
f) Enter sudo rm -r employee_data to delete the directory.
SCENARIO
The R&D team is concerned about unauthorized users tampering with the prototype data. There's
also the possibility that the data will become corrupted in a non-obvious way, which will
compromise the integrity of the data. So, in order to be confident that the data hasn't changed,
you'll run the files through a hash function and compare those hashes to hashes captured at a
different time. If the hash values are the same, you can be assured of the data's integrity. If not,
you'll know something went wrong.
________________________________________________________________________________
3. Make changes to the files and verify that they fail the integrity check.
a) Enter sudo bash -c "echo GPU999 >> prototypes/gpu.csv"
b) Enter sudo rm prototypes/hmd.csv
c) Enter sudo sha256sum -c hashes.txt
d) Verify that, this time, the integrity check failed on the file you modified, and that it could not
find the file you deleted.
SCENARIO
In order to enhance your productivity at the CLI, you decide to customize your Bash shell
environment. For security reasons, you want to minimize the number of commands that are kept in
the shell history, so you'll adjust the appropriate environment variable. You also plan on creating a
directory to hold your future scripts, and in order to easily execute the scripts in that directory, you'll
need to add it to your search paths. Lastly, as part of your auditing duties, you find yourself entering
a rather lengthy command at the CLI every so often; this can get tedious, so you'll create a short
alias for that command to make things easier.
________________________________________________________________________________
2. Reduce the maximum size of the command history by exporting its environment variable.
a) Enter echo $HISTSIZE and verify that the variable has the expected value.
b) Enter export HISTSIZE=5
c) Enter more than five unique commands, one after another. For example, you could enter
echo 1, echo 2, etc.
d) Press the Up Arrow and verify that you can only return, at most, to the fifth-most recent
command.
Note: You can revert the history size if you prefer, or you can log out and it will revert
automatically.
c) Enter testscript.sh
d) Verify that the command was not found.
b) Verify the current search paths that are set in this environment variable.
c) Ensure you are in your home directory.
d) Open .bash_profile in the text editor of your choice.
e) Scroll to the last line of the file and change it to say the following:
export PATH=$PATH:/scripts
Caution: Ensure you are appending /scripts to the $PATH variable, or you will overwrite the
existing paths and be unable to easily enter many commands.
SCENARIO
As part of managing the many storage partitions and volumes on your Linux servers, you routinely
run a command like df to see if any devices are getting close to full. By monitoring the storage space
being used by each device, you can avoid problems before they happen. However, entering this
command over and over again is somewhat tedious, and it doesn't immediately retrieve the most
relevant information in the most useful format. You want to be able to generate a more readable
"dashboard" report of what storage devices are getting close to full, and which are fine. So, you
decide to automate the process by writing a script to do the work for you.
________________________________________________________________________________
1. Create the script file and give yourself the necessary permissions to execute it.
a) Enter sudo touch /scripts/check_storage.sh
b) Enter sudo chown student## /scripts/check_storage.sh
The first line will simply echo the current date and time. It does this by leveraging the date
command using command substitution. The second line just makes the formatting a little
more visually pleasing; you don't need type an exact number of hyphens.
There's quite a bit being assigned to this variable. The following is a breakdown:
• First, the entire value is a command, so it uses the command substitution format, i.e.,
$(...)
• The first subcommand uses df to get drive information.
• This is piped to the grep command, which searches the results for anything matching the
$part variable you just defined (in this case, /dev/sda1).
• The awk command extracts the data in the fifth column of these results. If you issue df -
h by itself, you can see that the fifth column details the percentage of the storage device
that is being used.
• Lastly, the cut command simply strips the percent sign (%) from the value so that the
script can perform arithmetic on it.
• The ultimate result is just a single number that represents the percentage of storage
being used by the /dev/sda1 partition.
5. Write echo statements that report storage usage and indicate the check is complete.
a) On a new line 11, type the following:
echo "$part is $checkper% full."
c) Select Save.
Now, all output in this script will be redirected to a file, unless otherwise specified.
d) Change the echo statement on line 15 so that it reads:
echo "Storage check complete. Report saved to storage_report.txt." >&2
This will redirect the message to the CLI (through stderr) in order to bypass the exec
command.
e) Save the script.
SCENARIO
You want to make your script more useful to the administrators who will be receiving the reports.
You can do this by enabling the script to make decisions based on various conditions. So, you'll use
various if statements to output a different message for when the storage device meets certain
thresholds of percentage full. Devices that are very close to full will trigger an urgent message,
whereas those that are less full will trigger less urgent messages.
________________________________________________________________________________
In other words, the script chose the correct action to take based on the conditions you set.
Note: You'll test some of the other conditions in the next activity.
SCENARIO
Your script is coming along, but it still needs improvement. You want to be able to output the status
of all relevant storage partitions/volumes on the system, not just one or a few. You need a way to
programmatically test your conditions for each device, rather than hardcode device names in your
script—especially if the storage devices are likely to change. So, you'll leverage a for loop to iterate
over each recognized storage device to perform the necessary checks.
________________________________________________________________________________
2. Insert a for loop that will iterate through the part array.
a) Place your cursor at the end of line 10, then press Enter twice.
b) On a new line 12, type the following:
for i in ${part[*]}
This begins the for loop. The i variable is the iterator. The part variable is being referenced
as an array, with the asterisk (*) indicating all values in that array. For every index in the
array (i.e., every device name), the script will execute what follows.
c) Press Enter, and on line 13, type do
This begins the code that the loop will execute on each iteration.
d) Place your cursor at the end of line 28 and press Enter.
e) On line 29, type done
This terminates the for loop. The conditional statements within this loop will be executed
for each iteration.
Caution: The output file name and count have both changed.
SCENARIO
Periodically, the developers at Develetech need to execute a task after hours. The schedule is not
predictable and they need to be able to manage these tasks themselves. You will use the at
command to satisfy this requirement.
________________________________________________________________________________
Schedule a task to run for two minutes into the future from your current time.
a) In your home directory, use the touch command to create a file named fileA
b) Check the current time on your system.
c) Enter at now + 2 minutes to access the interactive mode of the command.
d) Enter rm -f ~/fileA and then press Ctrl+D to return to Bash.
e) Enter atq to view the scheduled job.
f) After two minutes, ensure that the command executed by checking the contents of your
home directory to see if fileA was removed.
SCENARIO
Develetech adopted a new policy that requires all users to fill in their time sheets every day. You'll
create a daily reminder for all user systems.
________________________________________________________________________________
2. Verify that Chris Mason received the reminder for the scheduled job.
a) Log in as Chris Mason.
Note: You can ignore the Welcome screen, or you can step through the wizard to dismiss it.
b) Open a terminal.
c) Wait for the time to pass for the cron job to execute.
Remember, you can use date to check the time. You can also check the time from the
desktop menu in the GUI.
d) Enter mail
e) Enter 1 to read the contents of the first email message.
f) Verify that the mail contains a reminder to fill in the time sheet.
g) Press q to quit the mail service.
h) Log out as Chris Mason and log back in as your student account.
SCENARIO
The development team needs a way to easily manage the different versions of the code they write.
Multiple developers will be working in conjunction on the same project, so they need to a way to
minimize conflicts while being able to revert to older versions of code, if necessary. So, you'll set up
a Git repository for the developers so that they have a distributed version control system to work
from.
________________________________________________________________________________
f) Enter git status and notice that there are now no changes to commit to the repository.
g) Enter git log to view the revision history of the repository.
Times and dates for the initial commit and the revision have been logged
SCENARIO
Now that your preparations are complete, you're ready to install Linux on the various systems you
selected. You'll start by installing CentOS 7 on the VM you created earlier. As you go through the
installation, you'll configure various options so that the base environment will be automatically set
up to your specifications.
________________________________________________________________________________
Note: You can also select the Switch to fullscreen view button.
b) On the WELCOME TO CENTOS 7 page, select Continue to accept the default language
settings.
c) On the INSTALLATION SUMMARY page, under the LOCALIZATION section, select DATE &
TIME.
d) Select your time zone, then select Done.
6. Configure networking.
a) On the INSTALLATION SUMMARY page, select NETWORK & HOST NAME.
b) In the Host name text box at the bottom-left, type devtech-vm## where ## refers to your
student number, then select Apply.
c) In the list of devices on the left, verify that Ethernet (eth0) is selected.
This is the virtual network interface that was created for the VM to use.
d) Select Configure at the bottom-right of the page.
e) In the Editing eth0 dialog box, select the IPv4 Settings tab.
f) From the Method drop-down list, select Manual.
g) To the right of the Addresses list, select the Add button.
h) For the Address, type 10.50.1.2## where ## is your student number.
For example, the IP address for student 01's VM would be 10.50.1.201
Note: Your instructor might provide you with different addresses than those listed in these
steps.