Lab 4 Navigating - The - Linux - Filesystem - and - Permission - Settings
Lab 4 Navigating - The - Linux - Filesystem - and - Permission - 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
Instructions
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,
2017 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 1 of 9 www.netacad.com
4.5.4 Lab - Navigating the Linux Filesystem and Permission Settings
/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)
<output omitted>
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)
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
Questions:
What is the meaning of the output? Where are the listed files physically stored?
Type your answers here.
2017 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 2 of 9 www.netacad.com
4.5.4 Lab - Navigating the Linux Filesystem and Permission Settings
[analyst@secOps /]$ cd ~
[analyst@secOps ~]$ ls –l
total 28
drwxr-xr-x 2 analyst analyst 4096 Sep 26 2014 Desktop
drwx------ 3 analyst analyst 4096 Jul 14 11:28 Downloads
drwxr-xr-x 9 analyst analyst 4096 Jul 25 16:27 lab.support.files
drwxr-xr-x 2 analyst analyst 4096 Mar 3 15:56 second_drive
-rw-r--r-- 1 analyst analyst 142 Aug 16 15:11 some_text_file.txt
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
Why is the directory no longer empty? Where are the listed files physically stored?
Type your answers here.
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)
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
2017 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 3 of 9 www.netacad.com
4.5.4 Lab - Navigating the Linux Filesystem and Permission Settings
Consider the cyops.mn file as an example. Who is the owner of the file? How about the group?
Type your answers here.
The permissions for cyops.mn are –rw-r--r--. What does that mean?
Type your answers here.
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.
[analyst@secOps ~]$ ls -ld /mnt
drwxr-xr-x 2 root root 4096 Jan 5 2018 /mnt
Type your answers here.
2017 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 4 of 9 www.netacad.com
4.5.4 Lab - Navigating the Linux Filesystem and Permission Settings
What can be done for the touch command shown above to be successful?
Type your answers here.
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
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)
Other: r-x (5 in octal or 101 in binary)
Question:
What command would change the permissions of myFile.txt to rwxrwxrwx, granting any user in the
system full access to the file?
Type your answers here.
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
2017 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 5 of 9 www.netacad.com
4.5.4 Lab - Navigating the Linux Filesystem and Permission Settings
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]$
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
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?
Type your answers here.
2017 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 6 of 9 www.netacad.com
4.5.4 Lab - Navigating the Linux Filesystem and Permission Settings
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 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 7 of 9 www.netacad.com
4.5.4 Lab - 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
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
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
2017 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 8 of 9 www.netacad.com
4.5.4 Lab - Navigating the Linux Filesystem and Permission Settings
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. Notice how it effects the linked files.
[analyst@secOps ~]$ mv file1.txt file1new.txt
[analyst@secOps ~]$ mv file2.txt file2new.txt
What do you think would happen to file2hard if you opened a text editor and changed the text in
file2new.txt?
Type your answers here.
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 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 9 of 9 www.netacad.com