CS558 Lab 1
CS558 Lab 1
You are required to explore the commands provided in the given files and analyze their
functionality. Additionally, You need to submit it in a report combining terminal screenshots.
Document when it is asked to do.
Objective:
To familiarize students with the basic and advanced Linux commands for file manipulation,
system navigation, process management, and network troubleshooting.
Prerequisites:
● Basic understanding of terminal and Linux operating systems (Commands are for
ubuntu).
● Access to a Linux-based system or a virtual machine running Linux.
Lab Exercise:
echo "Text goes here" > testfile.txt # Write a few lines to the file
echo "Additional line" >> testfile.txt # Append more text to the file
ls -l testfile.txt
ls -l testfile.txt Verify
ls -l testfile.txt Verify
ls -l testfile.txt Verify
ls -l testfile.txt Verify
ls -l testfile.txt
Step 2: Change the ownership of the file (replace 'username' and 'groupname'
with actual values)
ls -l testfile.txt
Just replace username and groupname with valid values for your system (e.g., faculty:students).
After running these commands, the ownership of testfile.txt will be updated, and the ls -l
command will show the new owner and group.
Document
● Set the file permissions of testfile.txt so that the owner can read and write, the
group can read, and others have no permissions.
● Add the setgid bit to a directory named shared to ensure new files inherit the
group.
● Set an ACL on example.txt to grant read permission to a user named alice.
ps aux
top
jobs
fg %1
Ctrl+Z
bg
kill 1234
kill -9 1234
find . -name testfile.txt # Search for 'testfile.txt' in the current directory and
subdirectories
grep "Text" testfile.txt # Search for the string "Text" within 'testfile.txt'
● find . -name testfile.txt searches for a file named testfile.txt starting from the current
directory (.) and includes all subdirectories.
● grep "Text" testfile.txt searches for the string "Text" inside the file testfile.txt.
● Redirection:
○ Use > to redirect the output of a command to a file (e.g., echo "Hello, Linux" >
output.txt).
○ Use >> to append output to an existing file.
○ Redirect both standard output and error output using 2>&1.
echo "Hello, Linux" > output.txt # Redirects the output of echo to 'output.txt'
# Step 3: Redirect both standard output and error output using 2>&1
command > output.txt 2>&1 # Redirects both stdout and stderr of 'command' to
'output.txt'
Explanation:
● >: Redirects the output of a command to a file, overwriting the file if it already exists.
● >>: Appends the output of a command to the end of an existing file.
● 2>&1: Redirects both standard output (stdout) and error output (stderr) to the same file
or stream. Here, 2 represents stderr, 1 represents stdout, and >&1 redirects stderr to
stdout.
1. Network Commands:
○ Check the IP address of your system using ifconfig or ip a.
○ Ping a remote server (e.g., ping google.com) to check network connectivity.
○ Use netstat to view open network connections (e.g., netstat -tuln).
Explanation:
Part 7: Command Line Basics (Terminal screenshot and document scripts.) [4 marks]
1. Use the command line to navigate to your home directory and create a subdirectory
named LinuxPractices.
2. Inside LinuxPractices, create a file named practice.txt, and enter some text into it using a
command line text editor (like nano or vi).
3. List all files in the LinuxPractices directory showing detailed information and redirect this
output to a file named details.txt.
4. Use command line tools to display the contents of practice.txt on the terminal.
5. Write a script that creates a backup of all .txt files in your Documents directory and
stores them in a Backup directory. Ensure the script checks if the Backup directory exists
and creates it if it does not.
6. The script should log each file it backs up with a timestamp in a log file named
backup.log.
7. Write a shell script that updates the system, cleans up temporary files, and shows
system information such as disk usage and memory usage. This script should log its
operations in a system log file.
8. Include error handling in the script to manage any potential failures during execution.
9. Write a script that requires administrator privileges, checks for them at the start, and
exits with an appropriate message if not run as root.
10. Include comments in your script to explain each section of the code and ensure it
adheres to best practices for security and performance.
Part 9: Basic User and Group Management (Terminal screenshot and document scripts.) [2 marks]
1. Create a new user account named johndoe with a home directory and a default shell of
/bin/bash.
2. Add the user johndoe to a new group named developers.
3. Change the username johndoe to johnsmith.
4. Delete the user johnsmith and ensure their home directory is removed.
Part 10: Monitoring and Managing Processes (Terminal screenshot and document scripts.) [2
marks]
1. Use the ps command to list all processes and save the output to a file named
ps_output.txt.
2. Install htop (if not already installed) and use it to monitor processes interactively.
3. Use the kill command to terminate a process by its PID (use a harmless process for this
task, such as a dummy script).
4. Change the priority of a running process using the renice command.
Part 11: Using System Monitoring Tools (Terminal screenshot and document scripts.) [2 marks]
To monitor system performance using essential Linux monitoring tools.
1. Use the vmstat command to monitor system performance for 1 minute with 5-second
intervals. Save the output to a file named vmstat_output.txt.
2. Use the iostat command to monitor disk I/O statistics every 10 seconds for 1 minute.
Save the output to a file named iostat_output.txt.
3. Install htop (if not already installed) and take a screenshot of htop running, showing CPU
and memory usage.
4. Use the mpstat command to monitor CPU usage per core every 5 seconds for 1 minute.
Save the output to a file named mpstat_output.txt.
Part 12: Configuring and Managing Logs (Terminal screenshot and document scripts.) [2 marks]
1. Configure rsyslog to log all authentication events (auth,authpriv.) to a custom log file
named /var/log/auth_custom.log.
2. Create a logrotate configuration that rotates /var/log/auth_custom.log daily, keeps 7 days
of logs, and compresses old logs.
3. Test the logrotate configuration using the logrotate command and provide the output.
Part 13: Analyzing and Searching Logs (Terminal screenshot and document scripts.) [2 marks]
1. Use grep to search for all failed SSH login attempts in /var/log/auth.log and save the
results to a file named ssh_failed_attempts.txt.
2. Use awk to extract and count the IP addresses involved in failed SSH login attempts.
Save the results to a file named failed_ips_count.txt.
3. Use sed to anonymize (replace with "REDACTED") a specific IP address (of your
choice) in /var/log/auth.log and save the modified log to a new file named
auth_redacted.log.
4. Use journalctl to display all systemd logs related to the sshd service for the last 24 hours.
Save the output to a file named sshd_journal.log.
----------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------