CPE 407 Lab Activity 3
CPE 407 Lab Activity 3
CPE 407 Lab Activity 3
Settings
Objectives
In this lab, you will use familiarize yourself with Linux filesystems.
Part 1: Exploring Filesystems in Linux
Part 2: File Permissions
Part 3: Symbolic Links and other Special File Types
Required Resources
• CyberOps Workstation VM
Instructions
© 2017 - 2022 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 1 of 23 www.netacad.com
Lab Activity 3 - Navigating the Linux Filesystem and Permission Settings
The output above shows that the CyberOps Workstation VM has three block devices installed: sr0, sda
and sdb. The tree-like output also shows partitions under sda and sdb. Conventionally, /dev/sdX is used
by Linux to represent hard drives, with the trailing number representing the partition number inside that
device. Computers with multiple hard drives would likely display more /dev/sdX devices. If Linux was
running on a computer with four hard drives for example, it would show them as /dev/sda, /dev/sdb,
/dev/sdc and /dev/sdd, by default. The output implies that sda and sdb are hard drives, each one
containing a single partition. The output also shows that sda is a 10GB disk while sdb has 1GB.
Note: Linux often displays USB flash drives as /dev/sdX as well, depending on their firmware type.
b. Use the mount command to display more detailed information on the currently mounted filesystems in the
CyberOps Workstation VM.
[analyst@secOps ~]$ mount
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
sys on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
dev on /dev type devtmpfs (rw,nosuid,relatime,size=1030408k,nr_inodes=218258,mode=755)
run on /run type tmpfs (rw,nosuid,nodev,relatime,mode=755)
/dev/sda1 on / type ext4 (rw,relatime)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
© 2017 - 2022 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 2 of 23 www.netacad.com
Lab Activity 3 - Navigating the Linux Filesystem and Permission Settings
<output omitted>
<paste the command output screenshot here>
Many of the filesystems above are out of scope of this course and irrelevant to the lab. Let’s focus on the
root filesystem, the filesystem stored in /dev/sda1. The root filesystem is where the Linux operating
system itself is stored; all the programs, tools, configuration files are stored in root filesystem by default.
c. Run the mount command again, but this time, use the pipe | to send the output of mount to grep to filter
the output and display only the root filesystem:
[analyst@secOps ~]$ mount | grep sda1
/dev/sda1 on / type ext4 (rw,relatime)
<paste the command output screenshot here>
© 2017 - 2022 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 3 of 23 www.netacad.com
Lab Activity 3 - Navigating the Linux Filesystem and Permission Settings
In the filtered output above, mount shows us that the root filesystem is located in the first partition of the
sda block device (/dev/sda1). We know this is the root filesystem because of the mounting point used: “/”
(the slash symbol). The output also tells us the type of formatting used in the partition, ext4 in this case.
The information in between parentheses relates to the partition mounting options.
d. Issue the following two commands below on the CyberOps Workstation VM:
[analyst@secOps ~]$ cd /
[analyst@secOps /]$ ls –l
<paste the command output screenshot here>
© 2017 - 2022 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 4 of 23 www.netacad.com
Lab Activity 3 - Navigating the Linux Filesystem and Permission Settings
Questions:
What is the meaning of the output? Where are the listed files physically stored?
The root directory is changed by the first command. The filesystems' root directory is at the top
level. By listing the files in the root directory, the user is actually listing files that are physically
stored at the root of the /dev/sda1 filesystem because /dev/sda1 is mounted on the root directory
("/").
Why is /dev/sdb1 not shown in the output above?
Because it is not currently mounted.
© 2017 - 2022 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 5 of 23 www.netacad.com
Lab Activity 3 - Navigating the Linux Filesystem and Permission Settings
Note: If the directory second_drive does not exist, use the mkdir second_drive command to create it.
[analyst@secOps ~]$ mkdir second_drive
Note: Depending on the state of your VM, your listing will most likely have different files and directories.
b. Use ls -l again to list the contents of the newly created second_drive directory.
[analyst@secOps ~]$ ls -l second_drive/
total 0
© 2017 - 2022 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 6 of 23 www.netacad.com
Lab Activity 3 - Navigating the Linux Filesystem and Permission Settings
Question:
Why is the directory no longer empty? Where are the listed files physically stored?
After mounting, /home/analyst/second_drive becomes the entry point to the filesystem physically
stored in /dev/sdb1.
e. Issue the mount command with no options again to display detailed information about the /dev/sdb1
partition. As before, use the grep command to display only the /dev/sdX filesystems:
[analyst@secOps ~]$ mount | grep /dev/sd
/dev/sda1 on / type ext4 (rw,relatime)
/dev/sdb1 on /home/analyst/second_drive type ext4 (rw,relatime)
<paste the command output screenshot here>
© 2017 - 2022 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 7 of 23 www.netacad.com
Lab Activity 3 - Navigating the Linux Filesystem and Permission Settings
f. Unmounting filesystems is just as simple. Make sure you change the directory to something outside of the
mounting point and use the umount command, as shown below:
[analyst@secOps ~]$ sudo umount /dev/sdb1
[sudo] password for analyst:
[analyst@secOps ~]$
[analyst@secOps ~]$ ls -l second_drive/
total 0
<paste the command output screenshot here>
© 2017 - 2022 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 8 of 23 www.netacad.com
Lab Activity 3 - Navigating the Linux Filesystem and Permission Settings
© 2017 - 2022 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 9 of 23 www.netacad.com
Lab Activity 3 - Navigating the Linux Filesystem and Permission Settings
Questions:
Consider the cyops.mn file as an example. Who is the owner of the file? How about the group?
Owner is “analyst” and the group is “analyst”
The permissions for cyops.mn are –rw-r--r--. What does that mean?
© 2017 - 2022 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 10 of 23 www.netacad.com
Lab Activity 3 - Navigating the Linux Filesystem and Permission Settings
The analyst user who owns the file can read and write to it but cannot execute it (-rw). Other than
the owner, members of the analyst group are only permitted to read files (-r-); no executing or
writing is permitted. No other users are permitted to modify or run that file.
c. The touch command is very simple and useful. It allows for the quick creation of an empty text file. Use
the command below to create an empty file in the /mnt directory:
[analyst@secOps scripts]$ touch /mnt/myNewFile.txt
touch: cannot touch '/mnt/myNewFile.txt': Permission denied
Questions:
Why was the file not created? List the permissions, ownership and content of the /mnt directory and
explain what happened. With the addition of -d option, it lists the permission of the parent directory.
Record the answer in the lines below.
The permissions of /mnt directory is owned by the root user, with permissions drwxr-xr-x. This
way, only the root user is allowed to write to the /mnt folder.
© 2017 - 2022 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 11 of 23 www.netacad.com
Lab Activity 3 - Navigating the Linux Filesystem and Permission Settings
What can be done for the touch command shown above to be successful?
The /mnt directory's permissions can be changed, or the command can be run as root by
appending sudo before it.
d. The chmod command is used to change the permissions of a file or directory. As before, mount the
/dev/sdb1 partition on the /home/analyst/second_drive directory created earlier in this lab:
[analyst@secOps ~]$ sudo mount /dev/sdb1 ~/second_drive/
e. Change to the second_drive directory and list the contents of it:
[analyst@secOps ~]$ cd ~/second_drive
[analyst@secOps second_drive]$ ls -l
total 20
drwx------ 2 root root 16384 Mar 3 10:59 lost+found
-rw-r--r-- 1 root root 183 Mar 3 15:42 myFile.txt
<paste the command output screenshot here>
Question:
© 2017 - 2022 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 12 of 23 www.netacad.com
Lab Activity 3 - Navigating the Linux Filesystem and Permission Settings
Question:
The chmod command takes permissions in the octal format. In that way, a breakdown of the 665 is as
follows:
6 in octal is 110 in binary. Assuming each position of the permissions of a file can be 1 or 0, 110 means
rw- (read=1, write=1 and execute=0).
Therefore, the chmod 665 myFile.txt command changes the permissions to:
Owner: rw- (6 in octal or 110 in binary)
Group: rw- (6 in octal or 110 in binary)
© 2017 - 2022 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 13 of 23 www.netacad.com
Lab Activity 3 - Navigating the Linux Filesystem and Permission Settings
What command would change the permissions of myFile.txt to rwxrwxrwx, granting any user in the
system full access to the file?
sudo chmod 777 myFile.txt
g. The chown command is used to change ownership of a file or directory. Issue the command below to
make root the owner of the myFile.txt:
[analyst@secOps second_drive]$ sudo chown analyst myFile.txt
[sudo] password for analyst:
[analyst@secOps second_drive]$ ls -l
total 20
drwx------ 2 root root 16384 Mar 3 10:59 lost+found
-rw-rw-r-x 1 analyst root 183 Mar 3 15:42 myFile.txt
[analyst@secOps second_drive]$
<paste the command output screenshot here>
© 2017 - 2022 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 14 of 23 www.netacad.com
Lab Activity 3 - Navigating the Linux Filesystem and Permission Settings
Note: To change both the owner and the group to analyst at the same time, use the sudo chown
analyst:analyst myFile.txt format.
h. Now that analyst is the file owner, try appending the word ‘test’ to the end of myFile.txt.
[analyst@secOps second_drive]$ echo test >> myFile.txt
[sudo] password for analyst:
[analyst@secOps second_drive]$ cat myFile.txt
<paste the command output screenshot here>
Question:
© 2017 - 2022 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 15 of 23 www.netacad.com
Lab Activity 3 - Navigating the Linux Filesystem and Permission Settings
© 2017 - 2022 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 16 of 23 www.netacad.com
Lab Activity 3 - Navigating the Linux Filesystem and Permission Settings
Question:
Compare the permissions of the malware directory with the mininet_services file. What is the difference
between beginning part of the malware line and the mininet_services line?
The permissions for the malware directory are preceded by the letter D at the start.
The letter ‘d’ at the beginning of the line indicates that the file type is a directory and not a file. Another
difference between file and directory permissions is the execution bit. If a file has its execution bit turned
on, it means it can be executed by the system. Directories are different than files with the execution bit set
(a file with the execution bit set is an executable script or program). A directory with the execution bit set
specifies whether a user can enter that directory.
The chmod and chown commands work for directories in the same way they work for files.
© 2017 - 2022 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 17 of 23 www.netacad.com
Lab Activity 3 - Navigating the Linux Filesystem and Permission Settings
o Image files
o Compressed files
• Directory files (d)
o Folders
• Special Files including:
o Block files (b) – Files used to access physical hardware like mount points to access hard drives.
o Character device files (c) – Files that provide a serial stream of input and output. tty terminals are
examples of this type of file.
o Pipe files (p) – A file used to pass information where the first bytes in are the first bytes out. This is
also known as FIFO (first in first out).
o Symbolic Link files (l) – Files used to link to other files or directories. There are two types: symbolic
links and hard links.
o Socket files (s) – These are used to pass information from application to application in order to
communicate over a network.
© 2017 - 2022 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 18 of 23 www.netacad.com
Lab Activity 3 - Navigating the Linux Filesystem and Permission Settings
b. Produce a listing of the /dev directory. Scroll to the middle of the output and notice how the block files
begin with a “b”, the character device files begin with a “c” and the symbolic link files begin with an “l”:
[analyst@secOps ~]$ ls -l /dev/
<output omitted>
crw-rw-rw- 1 root tty 5, 2 May 29 18:32 ptmx
drwxr-xr-x 2 root root 0 May 23 06:40 pts
crw-rw-rw- 1 root root 1, 8 May 23 06:41 random
crw-rw-r-- 1 root root 10, 56 May 23 06:41 rfkill
lrwxrwxrwx 1 root root 4 May 23 06:41 rtc -> rtc0
crw-rw---- 1 root audio 253, 0 May 23 06:41 rtc0
brw-rw---- 1 root disk 8, 0 May 23 06:41 sda
brw-rw---- 1 root disk 8, 1 May 23 06:41 sda1
brw-rw---- 1 root disk 8, 16 May 23 06:41 sdb
brw-rw---- 1 root disk 8, 17 May 23 06:41 sdb1
drwxrwxrwt 2 root root 40 May 28 13:47 shm
crw------- 1 root root 10, 231 May 23 06:41 snapshot
drwxr-xr-x 2 root root 80 May 23 06:41 snd
brw-rw----+ 1 root optical 11, 0 May 23 06:41 sr0
© 2017 - 2022 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 19 of 23 www.netacad.com
Lab Activity 3 - Navigating the Linux Filesystem and Permission Settings
c. Symbolic links in Linux are like shortcuts in Windows. There are two types of links in Linux: symbolic links
and hard links. The difference between symbolic links and a hard links is that a symbolic link file points to
the filename of another file and a hard link file points to the contents of another file. Create two files by
using echo:
[analyst@secOps ~]$ echo "symbolic" > file1.txt
[analyst@secOps ~]$ cat file1.txt
symbolic
[analyst@secOps ~]$ echo "hard" > file2.txt
[analyst@secOps ~]$ cat file2.txt
Hard
<paste the command output screenshot here>
© 2017 - 2022 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 20 of 23 www.netacad.com
Lab Activity 3 - Navigating the Linux Filesystem and Permission Settings
d. Use ln –s to create a symbolic link to file1.txt, and ln to create a hard link to file2.txt:
[analyst@secOps ~]$ ln –s file1.txt file1symbolic
[analyst@secOps ~]$ ln file2.txt file2hard
e. Use the ls –l command and examine the directory listing:
[analyst@secOps ~]$ ls -l
total 40
drwxr-xr-x 3 analyst analyst 4096 Aug 16 15:15 cyops_folder2
drwxr-xr-x 2 analyst analyst 4096 Sep 26 2014 Desktop
drwx------ 3 analyst analyst 4096 Jul 14 11:28 Downloads
lrwxrwxrwx 1 analyst analyst 9 Aug 17 16:43 file1symbolic -> file1.txt
-rw-r--r-- 1 analyst analyst 9 Aug 17 16:41 file1.txt
-rw-r--r-- 2 analyst analyst 5 Aug 17 16:42 file2hard
-rw-r--r-- 2 analyst analyst 5 Aug 17 16:42 file2.txt
drwxr-xr-x 9 analyst analyst 4096 Jul 25 16:27 lab.support.files
drwxr-xr-x 3 analyst analyst 4096 Mar 3 18:23 second_drive
-rw-r--r-- 1 analyst analyst 142 Aug 16 15:11 some_text_file.txt
-rw-r--r-- 1 analyst analyst 254 Aug 16 13:38 space.txt
© 2017 - 2022 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 21 of 23 www.netacad.com
Lab Activity 3 - Navigating the Linux Filesystem and Permission Settings
Notice how the file file1symbolic is a symbolic link with an l at the beginning of the line and a pointer ->
to file1.txt. The file2hard appears to be a regular file, because in fact it is a regular file that happens to
point to the same inode on the hard disk drive as file2.txt. In other words, file2hard points to the same
attributes and disk block location as file2.txt. The number 2 in the fifth column of the listing for file2hard
and file2.txt indicates that there are 2 files hard linked to the same inode. For a directory listing the fifth
column indicates the number of directories within the directory including hidden folders.
f. Change the names of the original files: file1.txt and file2.txt, and notice how it effects the linked files.
[analyst@secOps ~]$ mv file1.txt file1new.txt
[analyst@secOps ~]$ mv file2.txt file2new.txt
© 2017 - 2022 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 22 of 23 www.netacad.com
Lab Activity 3 - Navigating the Linux Filesystem and Permission Settings
Notice how file1symbolic is now a broken symbolic link because the name of the file that it pointed to
file1.txt has changed, but the hard link file file2hard still works correctly because it points to the inode of
file2.txt and not its name, which is now file2new.txt.
Question:
What do you think would happen to file2hard if you opened a text editor and changed the text in
file2new.txt?
Because they both point to the same inode on the hard disk drive, changing the contents of one
file would also modify the contents of the other.
Reflection
File permissions and ownership are two of the most important aspects of Linux. They are also a common
cause of problems. A file that has the wrong permissions or ownership set will not be available to the
programs that need to access it. In this scenario, the program will usually break and errors will be
encountered.
End of document
© 2017 - 2022 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 23 of 23 www.netacad.com