Skip to content

Latest commit

 

History

History
283 lines (195 loc) · 4.61 KB

File metadata and controls

283 lines (195 loc) · 4.61 KB

Linux

This module does not cover any concrete, thorough practical exercises, rather basic tasks pertaining to the following aspects of Linux system administration:

Table of Contents

Command Line Basics

Navigation Tasks

Note the current directory, then change to the directory /etc and list its contents.

pwd
cd /etc
ls -la

File 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.txt

Clean up

rm -r test_directory

User and Permission Management

Users and Groups

Create a new user testuser and create a new group testgroup.

sudo useradd testuser
sudo groupadd testgroup

Assign testuser to the group testgroup.

sudo usermod -aG testgroup testuser

Verify that the user was correctly created and assigned to the group.

id testuser

File 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.txt

Set 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.txt

Change the owner of the file to testuser and the group to testgroup.

sudo chown testuser:testgroup /home/testuser/example.txt

Check the permissions.

ls -l  /home/testuser/example.txt

Clean up

sudo userdel -r testuser
sudo groupdel testgroup

System Administration and Process Management

Process Monitoring

Display running processes.

ps aux

Live system monitoring using:

top

Process Control

Terminate a process.

# Determine the PID of the previously run top command
ps aux | grep top
# Terminate the process
kill 8476

Change 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 10

Log Analysis

Observe the logs.

tail -f /var/log/syslog

Filter error messages with grep.

tail -f /var/log/syslog | grep errror

Package Management

Update the system.

sudo apt update && sudo apt upgrade

Install curl and htop.

sudo apt install curl && sudo apt install htop

Networking Basics and Security Concepts

Display your current interfaces and IP addresses.

ip addr show

Check the reachability of an external host.

ping google.com

Show open ports.

ss -tuln

Test-block a port that is not needed.

sudo iptables -A INPUT -p tcp --dport 8080 -j DROP

Check if the rule is active.

$ sudo iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
DROP       tcp  --  anywhere             anywhere             tcp dpt:http-alt

Delete the rule again.

sudo iptables -D INPUT -p tcp --dport 8080 -j DROP

Explicitly allow SSH access (port 22).

sudo ufw allow 22

Activate the firewall.

sudo ufw enable

Check the active rules.

$ sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
22                         ALLOW       Anywhere
22 (v6)                    ALLOW       Anywhere (v6)

Troubleshooting

Log Analysis

Observe running logs.

tail -f /var/log/syslog

Filter specifically for errors.

grep -i fail /var/log/syslog

Error Diagnosis

Stop a service.

sudo systemctl stop ssh

Check error sources.

systemctl status ssh
journalctl -xe

Create a backup of /etc directory.

sudo tar -czf etc-backup.tar.gz /etc/

Check the archive.

tar -tf etc-backup.tar.gz