This module does not cover any concrete, thorough practical exercises, rather basic tasks pertaining to the following aspects of Linux system administration:
Navigation Tasks
Note the current directory, then change to the directory /etc and list its contents.
pwd
cd /etc
ls -laFile Management Tasks
Create a new directory named test_directory and change to this directory. Create a text file notes.txt there and copy it to a file notes_backup.txt.
mkdir test_directory
cd test_directory
touch notes.txt
cp notes.txt notes_backup.txt
Editing File Contents
Open notes.txt, insert some text lines and save the file. Then display the content of the file.
vi notes.txt
# Insert the text:
# Hello World!
cat notes.txtClean up
rm -r test_directoryUsers and Groups
Create a new user testuser and create a new group testgroup.
sudo useradd testuser
sudo groupadd testgroupAssign testuser to the group testgroup.
sudo usermod -aG testgroup testuserVerify that the user was correctly created and assigned to the group.
id testuserFile Permissions
Create a file example.txt in the home directory of testuser.
# Check the home directory of testuser
sudo cat /etc/passwd
# home directory: /home/testuser
sudo touch /home/testuser/example.txtSet the file permissions so that the owner has read, write, and execute rights and the group and others have only read and execute rights.
sudo chmod 755 /home/testuser/example.txtChange the owner of the file to testuser and the group to testgroup.
sudo chown testuser:testgroup /home/testuser/example.txtCheck the permissions.
ls -l /home/testuser/example.txtClean up
sudo userdel -r testuser
sudo groupdel testgroupProcess Monitoring
Display running processes.
ps auxLive system monitoring using:
topProcess Control
Terminate a process.
# Determine the PID of the previously run top command
ps aux | grep top
# Terminate the process
kill 8476Change the priority of a process.
$ sudo nice -n -5 top
# determine the PID of top process
$ ps aux | grep top
$ sudo renice +10 8528
8528 (process ID) old priority -5, new priority 10Log Analysis
Observe the logs.
tail -f /var/log/syslogFilter error messages with grep.
tail -f /var/log/syslog | grep errrorPackage Management
Update the system.
sudo apt update && sudo apt upgradeInstall curl and htop.
sudo apt install curl && sudo apt install htopDisplay your current interfaces and IP addresses.
ip addr showCheck the reachability of an external host.
ping google.comShow open ports.
ss -tulnTest-block a port that is not needed.
sudo iptables -A INPUT -p tcp --dport 8080 -j DROPCheck if the rule is active.
$ sudo iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
DROP tcp -- anywhere anywhere tcp dpt:http-altDelete the rule again.
sudo iptables -D INPUT -p tcp --dport 8080 -j DROPExplicitly allow SSH access (port 22).
sudo ufw allow 22Activate the firewall.
sudo ufw enableCheck the active rules.
$ sudo ufw status
Status: active
To Action From
-- ------ ----
22 ALLOW Anywhere
22 (v6) ALLOW Anywhere (v6)Log Analysis
Observe running logs.
tail -f /var/log/syslogFilter specifically for errors.
grep -i fail /var/log/syslogError Diagnosis
Stop a service.
sudo systemctl stop sshCheck error sources.
systemctl status ssh
journalctl -xeCreate a backup of /etc directory.
sudo tar -czf etc-backup.tar.gz /etc/Check the archive.
tar -tf etc-backup.tar.gz