CSEC-378-418-Lab1-v3
docx
keyboard_arrow_up
School
Oakton Community College, Des Plaines *
*We aren’t endorsed by this school
Course
145
Subject
Information Systems
Date
Feb 20, 2024
Type
docx
Pages
19
Uploaded by MajorQuetzalMaster278
Full Name: ___HET Patel______
Date/Time Started: _02/16/24 3:53 PM___
CSEC 378/418 - Lab 1
Deliverable and Instructions:
This lab will guide you through the configuration and management of your Linux system. This lab begins once you are already connected to your Linux host through the Netlab environment. For instructions on
how to get connected to the Netlab environment, please consult the Lab Connectivity Guide on D2L.
During the course of this lab you will create a user with a username consisting of your first initial and last
name - i.e. knaughton. Throughout this lab when you see the term yourname
, I am referring to this user
account. Substitute it in commands accordingly with the correct username. Please do not create a user actually named “yourname”. I use the presence of your username in screenshots to validate that the screenshots are your own, and you will not receive credit if you do not have a unique username.
The submission file for this lab will be a pdf version of this document, with your answers and screenshots added. Each correctly answered question will count for 1 point. Each screenshot will also count for 1 point and will be evaluated on whether it fully meets the requirements of the screenshot prompt. Your score will be determined by the percentage of total questions and screenshot prompts answered correctly.
Answer the questions below the prompts indicated in green. If the question is multi-part, you must answer all parts correctly to receive the point for that question. No partial credit will be given.
Add screenshots below the prompts indicated in green. If your screenshot does not meet the requirements of the prompt you will not receive credit for that screenshot. Each individual question is worth 1 point. Each individual screenshot prompt is worth 1 point.
Ensure that each screenshot is readable in-line in the submission document. If I am unable to read the contents of your screenshot in the document because it is too large of a
screenshot, it will not count for credit. Do not include screenshots of your whole desktop or whole
terminal window to when the prompt is asking about one single command.
Section 1: File & Directory Management Step 1:
Use the Netlab environment to access your “Linux Server 1” machine as the student user. You will not need to use any of the Windows machines for this lab. They will be used in a future labs. Login with the username student and the password student
. Once logged in you will see a prompt similar to the one below.
Question 1.1:
What do the different components of the prompt mean? Explain each part of the prompt.
“Student” means the current username that is currently being logged into the Linux server 1. “@” means that it’s a symbol that separates the hostname from the username. “~” means that it is currently in the home directory of the currently logged-in user. “$” means that the user that is logged in is a regular user.
Question 1.2:
By looking at this prompt are you a normal user or a super user? How do you know?
I am a normal user and I know this because by looking at the symbol “$”
Step 2:
Enter the date command by typing date into the shell prompt.
Include a screenshot of the output of the command.
Step 3:
Use the passwd
command to change the password of the student user you are logged in as. Just
enter the passwd
command with no arguments to change the password of the user you are logged in as.
Step 4:
When prompted, enter the current password for the student
account.
Step 5:
When asked to enter a new password enter the password
CSEC378418! And then enter it again to finish changing this password.
Step 6:
Create a new file with the touch
command. touch is a command that can be used to update the timestamp on an existing file or create a blank new file if used on a filename that doesn’t already exist. Use the touch
command to make a file called yourname.txt. For example, I would run the command touch knaughton.txt
to create my file.
Step 7: Use the ls
(list) command to list the contents of your current directory and include a screenshot of the output of the command. You should be able to see the file you just created.
1
v2
Step 8:
The file
command will tell you some details about the file type and contents of a file. Use the file
command on your new text file and include a screenshot of the output below.
Question 1.3:
What does the file command you used in the last step tell you about the file you specified?
The file command tells me that there is nothing inside the file that I just opened hpatel.txt. Step 9: Lets add some contents to the file you just created. One of the quickest ways to do this is to redirect some contents into the file. echo
is a utility that will take whatever input you give it and echo it back to you. Try running the command echo hello world
and see what happens.
Step 10:
echo
takes text in via standard input (stdin) and spits it back out at you via standard output (stdout)
. We can redirect that output using the >
character and send it to a file, rather than just to your screen. Try rerunning the command from the last step but now we will add an output redirect like so: echo hello world > knaughton.txt
Step 11:
Now use the file
command again on the text file. Include a screenshot
of the output here.
Question 1.4:
What changed about the output of the file command, why is it different?
One thing that changed was from empty to “ASCII text” and it’s different from before because the text inside the file can be read by a human.
2
v2
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Step 12:
Run the following command: head /etc/passwd to display the top 10 lines of this file. Include a screenshot
of the output here.
Question 1.5: Why are there no passwords contained in this file? What file actually stores passwords?
There are no passwords in this file because it’s a basic database for users and anyone can access this file.
The file that stores the password in /etc/shadow and it can be used by the root user.
Step 13:
Now run the following: head -n 3 /etc/passwd and take a look at how the output differs from the last step.
Question 1.6:
What do the command, option, and argument used in the previous step do? Explain each.
The command shows the output in the first few lines. The -n option shows the line number and then the 3 shows how many total lines are there in the output. Step 14:
Research and find a command that can be used to only display the last 5 lines of a file. Use the command and include a screenshot of your output below.
Question 1.7:
Explain what the command you used in the previous step does and explain any options you used.
The command that I used was the tail command and it outputs the last few lines of the file. The -n option in the command shows the line number and then 5 shows how many lines are in the output.
Step 15:
Use the cd (change directory) command to move around the file system. Enter the command cd / to change your directory from the student user’s home directory to the system’s root directory (which is represented by a “/”). 3
v2
Step 16:
Use the command ls
to see which directories are contained here, and then move into one of them using cd
, then use pwd
to show where you are.
Include a screenshot
after running these commands below.
Note:
You can move through more than one directory at a time if you specify the whole file path. Let’s
try this in the next step.
Step 17:
From your current location, use the command cd /home/student Question 1.8:
Is the file path used in the last step an example of a relative path or an absolute path? How do you know?
The file path that is used in the last step is absolute because the location is specified as a “/” directory. Step 18:
Use the pwd
(print working directory) command to display what directory you are currently working in. Include a screenshot
of your output below.
Step 19:
Use the touch
command again to create a blank file named testfile.txt in the student user’s home directory.
Step 20:
After creating the file, use ls
again, but this time use the options -l
(lowercase L) and -t
to list out the files in this directory and include a screenshot
to display that you have created a file named testfile1.txt in the /home/student directory.
Question 1.9:
What do the -l and -t options do? How did they change the output of the ls command?
The -l and -t options list all the files from the /home/student directory. The ls command will change the output by providing more details on the files and letting the user read and write the files.
4
v2
Step 21:
Use the command mkdir
(make directory) to create a new directory called Lab1 using the command mkdir Lab1
. Since you are currently in /home/student, this new directory will be created there.
Step 22:
Use ls -lt again to view the newly created directory, and then use the file
command on the Lab1
directory. Include a screenshot
of the output of both commands below.
Question 1.10:
Without using the file
command and without using the color-coded file names, how would you be able to tell that Lab1 is a directory based on the output of ls -lt
?
We can tell that lab1 is a directory because of the output of ls -lt and by using the command mkdir to make lab1 a directory. Step 23:
Use the cp
(copy) command to make a copy of testfile.txt using the following command: cp testfile.txt testfile2.txt After running this command use the ls -lt
command again and include a screenshot
of your output.
Question 1.11:
Explain what the cp command in the last step is doing. Why doesn’t it remove the original file?
The cp command in the last file is basically making a copy of testfile.txt into textfile2.txt. It keeps the old file and the new file as well. The file has the exact same content in it.
Step 24:
Now use the mv
(move) command to move testfile2.txt to the Lab1 directory by entering the following command mv testfile2.txt Lab1/
Step 25:
Use the ls -lt
command twice to show the contents of your home directory and also the Lab1
directory and include a screenshot
of the commands and output below.
5
v2
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Step 26:
Try to copy the Lab1 directory using cp Lab1 LabOne.
This will not work because Lab1 has contents, but you will receive a helpful error message. Figure out how to use cp to copy the Lab1 directory and all of its contents into a new directory named LabOne. Include a screenshot
of the command you used to achieve this, along with the output of ls -lt
showing that it worked.
Note:
Use Google, or you can use the man
(short for manual) command to look at all the available
options for the cp
command by using man cp
. You can use man on any bash command to see options.
Step 27:
Use the rm
(remove) command to delete the file testfile.txt with the command rm testfile.txt
. Then, use ls -lt
and include a screenshot
below of both commands.
Step 28:
Try to use the rmdir
(remove directory) to remove the Lab1 directory with the command rmdir Lab1.
It will not work
.
Question 1.12:
Why can’t you use the rmdir
command to delete the Lab1 directory in the previous step?
The lab1 directory is not empty so we can’t use rmdir to delete and Linux will also not allow us delete if it’s not empty. Step 29:
Use rm to delete the testfile2.txt file located in the Lab1 directory. Then try to use rmdir on Lab1 again.
Include a screenshot
showing that you were able to delete the Lab1 directory.
6
v2
Note:
If your screen is getting too cluttered with command output, you can always use ctrl+l (lowercase
L) to clear your screen. You can also type clear
to clear the screen as well.
7
v2
Section 2: Users, Groups, and File Permissions Step 1:
Try to use the adduser command to add a user (using the first initial of your first name, full last name, all lowercase, no spaces – i.e. mine would be knaughton
) with the command adduser yourname
This will not be successful.
Note:
From here on out, when you see references to the yourname
user, this is a reference to this user
account. Substitute it in commands accordingly with the correct username. Do not create a user named “yourname” or “knaughton”. If you do, your screenshots will not count.
Step 2:
Creating a user requires additional permissions. You will need to use the sudo
command (super user do) before adduser
in order to elevate your permissions for this command. Try again with the command sudo adduser yourname
. Step 3:
You will be prompted for authentication to use the sudo command. Enter the student user’s CSEC378418! password when prompted. Step 4:
You will be prompted for the new user’s password and some other information. When prompted
for a new password, enter the password Chicago1871! You can leave the other entries (Full name, room number, etc) blank.
Step 5:
Use the id
command on the newly created yourname
user. Include a screenshot
of the output.
Question 2.1:
Specify what uid, gid, and groups mean in the output. Uid means to the output that a number value that represents in the id hpatel. Gid means a number that identifies the group for the system in hpatel. Groups means that a number in the system that shows the group id number and also shows which group can access which certain files. Step 6:
All users have an entry added to the /etc/passwd file when they are created. Let’s look at the file
by reading the last line of the /etc/passwd file using the tail command. The new user will be the bottom entry in the file, so outputting the last line will show you this new entry. Paste a screenshot below
of the command and the output.
Step 7:
To change users from the student user to the newly created yourname
user you will use the su
(switch user) command: su yourname
. By entering yourname
’s password Chicago1871!
you can switch to this account.
8
v2
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Step 8:
Use the id
command you used in Step 5 on both the student and yourname
accounts and look at
their group membership. Include a screenshot
of your results below.
Question 2.2:
Which account has more privileges? How do you know?
The student account has more privileges and I know that because the group wheel means that it can access two groups in the system. Step 9:
Try to run any command using sudo
while logged in as yourname
.
Question 2.3:
In your own words (don’t just give me the error message), why doesn’t this work?
The account hpatel doesn’t have access to the sudo command. Step 10: You will need to grant the yourname account access to the sudo binary, but you cannot make these changes unless the account you are currently using has permission to make these changes. Use exit to switch back to the student
account, which already has permission to use sudo
.
Note: The exit
command works here because you were originally logged in as student
, and then used su
to switch to yourname
. exit lets you jump back to your previous user in this case, but you could also use
su student
to switch to student as well.
Step 11:
As student
,
use the gpasswd
command to add yourname
to the group called wheel
, which will grant yourname
permission to use sudo.
Use the following command to do this: sudo gpasswd -a yourname wheel
. After doing this, use the id command on yourname
to verify that yourname is now a member of the wheel group. Include a screenshot of the output of both
commands.
Note: Any member of the wheel group has permission to use sudo commands. The name of this group is
a relic from the early days of unix/linux, but the convention is still used.
Question 2.4:
If we wanted to remove a user from a group using gpasswd, what would the command be? Use Google, or try man gpasswd
to find the answer. The command would be “gpasswd -d user_namegroup_name”
Note: There are multiple commands that can be used to modify a user’s group membership. gpasswd is
just one of these commands. gpasswd has the ability to modify group passwords, as well as some other
group features, thus its name (group password). Here, we simply use it to add a user to a group.
9
v2
Step 12:
Now that you have the ability to use sudo as the yourname account, use the su command to switch back to the yourname
account. By default you will still be in the student user’s home directory. Switch to your new user’s home directory by issuing the cd
command with no arguments, which will take you home.
Step 13:
You can view all groups that are configured on a system by reading the /etc/group file. To do this run the command
less /etc/group
.
less
is a useful command that can be used to view and scroll through files without editing them. However, when files get large, it’s unreasonable to scroll through the whole file looking for a single line manually. When using less
you can search a file by typing /
followed by your search term, and then enter. Search for the wheel group and include a screenshot
of the wheel group and its listed members. Press q
to exit from viewing the file.
Note: When managing a Linux system, it is best practice to use the root account as infrequently as
possible. Everyone should use a different user account with sudo permissions for day-to-day system
administration. On a system with multiple users, this will help keep track of individual user’s actions. If
everyone just logs in as root, you will not be able to tell individual user actions apart.
Step 14:
Add a new group using the command groupadd
followed by the name of the group we want to create. Create a group called depaulcdm
and then add yourname to this group with gpasswd
. You will likely get errors if you attempt to run these commands
directly. Any time you receive errors like this, try
using sudo to elevate your permissions for that command.
Step 15:
Verify that this group has been added to the /etc/group
, you should also see yourname
listed as the only member
.
Include a screenshot of the new group in the /etc/group file.
Step 16:
You can change attributes of an existing group using the groupmod
command. Use groupmod to rename the depaulcdm group to depaul
. Use Google or man groupmod
to find the right command options. Include a screenshot of the command you used.
Question 2.5:
Check the /etc/group file again. Is yourname
now a member of the depaul
group? What happened to the depaulcdm group?
Yes my hpatel is now a part of depaul group. It is no longer in the /etc/group because we changed the group name to depaul Step 17
: Use the cd command without any arguments to move to your home directory. Typing just cd
will always bring you back to your configured home directory. Use the pwd command to verify that you are in /home/yourname
.
10
v2
Step 18: There is currently nothing in yourname’s home directory. You can verify this with ls
. Use vim to start editing a new file. Use the command vim newfile.txt
to begin editing. You will be presented with a blank file. vim
can be used to view files, as well as edit them. By default, when you open a file in vim you are in command-mode, which does not have the ability to edit. To enter insert-mode and be able to edit, press i
. Enter the following three lines into this new file.
Hello World!
This is my new file.
Signed, yourname
When you are finished typing, you will still be in insert mode. To back out to command mode again, press escape. Try exiting vim by typing :q
(the :
is part of the command) you will receive an error message. Vim is not going to allow you to quit the file until you indicate whether to save or discard the changes you made. To force vim to quit include an !
in your exit command like this :q!
Step 19:
Now use ls to list all files in your directory. To your dismay, the newfile.txt is not here! When you exited vim, you didn’t save your changes. Since vim was forced to quit without saving, your changes
were discarded.
Step 20:
Do Step 18 again and recreate your file. However at the end, instead of using :q! (quit, force) to
exit, use :wq
(write changes, quit) to save your changes and quit.
Note:
vim may seem confusing at first, mainly because it uses a lot of keyboard shortcuts. If you’re new
to vim, you may accidentally trigger these shortcuts, leading to unexpected behavior. Practice makes
perfect with vim. When you get good with the shortcuts, you can very quickly move around and edit a
file. When you are learning vim, if you ever end up stuck and can’t figure out how to exit, try pressing
escape a few times before trying the :q or :wq
commands.
If you are struggling with maneuvering around in vim, check out this quick tutorial on YouTube that
covers the basics: https://youtu.be/ggSyF1SVFr4?t=53
Step 21: Use ls
again. Now you will see your newfile.txt sitting in your home directory. Use mkdir
to make a new directory called newdir using the command
sudo mkdir newdir
. Use ls -lt
to see the newfile.txt and the newdir. Include a screenshot of the output.
11
v2
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Question 2.6: Based on the command output, which user and group owns newfile.txt? Which user and group owns newdir? Why are they not the same?
Hpatel owns the newfile.txt and then root owns the newdir. They are not the same because we created the new directory using the root Question 2.7:
The output of ls -lt
includes a string of letters and dashes in the left most column. What does the first character of this string indicate? What does it mean if it is a d
?
D is for the directory.
Question 2.8:
The other characters in the string of letters and dashes indicate file permissions. What is meant by rwx? Why are there three sets of rwx’s?
R is for read and w is for write and x is for run. Since it has users, groups and other right. Step 22:
Next, we will change the permissions on our newfile.txt file. Issue the command chmod 700 newfile.txt
. Then issue ls -lt
again to see the new permissions.
Question 2.9: What changed? Who has access to this file now?
Two things that changed was the groups and permission rights and only hpatel has access to this file. Question 2.10:
What does the “700” mean in the chmod 700
command?
700 means full rights to the user and no groups and no other user. Step 23: Use the su
command to change your user to the student
user. As student
, try to read the file using the command less newfile.txt
. It should fail, indicating that you do not have permissions as the student user.
Question 2.11:
Without changing your user, or modifying the file permissions - What command can you use to view this file? Why are you able to read the file with that command, despite student not having permissions to view?
Sudo less newfile.txt. The reason why I was able to see the file was because of the sudo command. Step 24
: Switch back to the yourname
account.
Step 25:
Use the cat
command to print the contents of newfile.txt to the screen using cat newfile.txt
. The cat
command will print the contents of a file to the screen, rather than enter you into an interactive file viewer or text editor. This can be useful for quickly viewing small files, or filtering output.
Step 26:
cat
is simple, but useful. If we want to redirect or trim the output of cat
, we can use some other operators and commands to do so. Let’s say we only want to see lines that contain the word “Hello”. Issue the command cat newfile.txt | grep Hello
The pipe “
|
” will redirect the output of the cat command to a handy utility called grep
. grep
will search for any line containing “Hello” and print only those lines. By doing this, we are filtering our output from cat
through grep
, to display only what we want to see. Post a screenshot
of the command and the output.
12
v2
Step 27:
You can redirect output with more than just |
. Building on the command from the last step, you
will now redirect the output of that command to a new file called secondfile.txt
. To do this, use >
to redirect the output of the command somewhere else. Issue the command
cat newfile.txt | grep Hello > secondfile.txt then take a look at the contents and the
file permissions of secondfile.txt. Include a screenshot
of the commands you used to check permissions and the contents of the secondfile.txt
.
Question 2.12: Why does secondfile.txt only contain one line?
It only shows one line because we used the cat command to only show the hello line and then save it in the secondfile.txt
Question 2.13:
Did this process copy over the file permissions from newfile.txt to secondfile.txt? How do
you know?
The process did not copy over and I know it because I used ls -lt to view the file permissions for all of the
files Step 28:
Construct and execute a chmod command that will make it so that the owner and
owning group have only read permissions
over secondfile.txt, but everyone else has no permissions. Include a screenshot
of the command you used, and proof that the permissions are correct.
Note: Ensure that the file permissions on your two files are correct before moving to the next step. The
permissions should be the same as the screenshot below.
13
v2
Step 29:
Change the ownership of the two text files you created. To do this use the chown (change owner) command. chown
allows you to specify more than one file as an argument.
Use the following command: sudo chown student newfile.txt
secondfile.txt
Using ls -lt
, note that the owner of both files has been changed to student, buy yourname’s group still has ownership. Include a screenshot
.
Question 2.14:
Now try to read the contents of both newfile.txt
and secondfile.txt
. Only one will still be viewable to the yourname
user. Which file can you still view? Why are you able to view this file, but unable to view the other file?
I was able to view the secondfile.txt and I was able to see this film because I have permission to read for the group in secondfile.txt.
Step 30:
In the last step, we changed the owner of these files, but left the groups alone. Now let’s change the group ownership with the chgrp
(change group) command. chgrp
also allows you to specify more than one file as an argument.
Issue the following command: sudo chgrp student newfile.txt
secondfile.txt
Again, using ls -lt
, note that the group owner of both files has been changed to student. Include a screenshot
.
Question 2.15:
Try to read the contents of both newfile.txt
and secondfile.txt
. Why are you now unable
to read the file that you were able to read in the previous question?
Now I can’t see it since I don’t have any permissions and it’s not part of the group. 14
v2
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Section 3: Logging and Time Configuration Step 1:
Run the su command with no username specified to try and switch to root. Purposely get the password wrong a few times. Do not actually switch your user, stay as yourname
.
Step 2:
Change directories to the /var/log/ directory and run the command sudo tail auth.log
. This will output the last 10 entries in the /var/log/auth.log file. Paste a screenshot
of the output you receive below.
Question 3.1:
Find one of the logs from your failed authentication attempts. Explain to the best of your knowledge what each component of the log means.
Question 3.2:
Run the command sudo tail auth.log
again. Now you will also see log messages for the tail
command you ran in the last step. Why was this command logged in the /var/log/auth.log
file?
Step 3:
Logging is done through a service called rsyslogd. This service monitors the logs generated on, and sent to the system, and decides which file to place them in the /var/log/ directory. View the rsyslogd config file and see where these rules are listed. Navigate to the /etc/
directory and view the rsyslog.conf file using less.
Search to find the RULES section of the configuration file. Search in less
is case sensitive. Take a screenshot
when you find this section and paste it below.
15
v2
Step 4:
Quit out of the file. Now use the command logger to manually send log messages to the log files.
This command would be useful if you were to change any of the default locations of the log files that you saw in the last step and wanted to test the functionality. Add a log file entry that says Testing log message for yourname We will place this message in the auth.log
file that is located in /var/log/
To put this command in place enter logger -p auth.info "Testing log message for yourname”
Step 5:
Use tail to see the contents of auth.log file and include of screenshot
showing the log message that you sent in the previous step.
16
v2
Step 6:
rsyslogd stores small bits of information about an incident to save space and to make it easy to spot issues. To see more information about these issues we need to use the systemd journal. The journal can be found in /run/log but is cleared upon restart by default. Look at the system journal using the command sudo journalctl
you can use the space bar to tab through the output, and q
to quit.
Step 7:
As you probably noticed, viewing the entire system journal is not very friendly to read. You can sort through entries in the system journal by message type using the option -p
on the journalctl command. Use the man page for journalctl
to figure out how to filter for errors using -p
, and how to limit the number of messages you see to 3. Paste a screenshot
below showing the command you ran and the output.
Note:
man
pages are searchable with / just like less
Step 9:
Accurate timestamps are very important for log analysis. Logs with incorrect time stamps can make it difficult to diagnose a problem or determine when an issue occurred. To get information on your
system and its time configuration run the command timedatectl Paste a screenshot
of the output below.
17
v2
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Step 10:
If you needed to switch time zones after moving a server to a different office location you can check to see the available time zones using the command timedatectl list-timezones
Question 3.3:
Research and explain in your own words: What is chronyd
, and what does it do?
Chronyd is a daemon for syncing all the clocks together. Date/Time Completed:__02/16/24_____7:43__
Estimated time it took you to complete this lab:__4 hour ___
18
v2