This repository documents essential Linux server administration tasks focusing on user management, system monitoring, performance analysis, security configuration, and web server setup. These tasks ensure efficient and secure operations for a development team.
Before starting, ensure you have:
- A Linux-based server (e.g., Ubuntu 20.04/22.04)
- Superuser (sudo) privileges to execute administrative tasks
- A basic understanding of Linux commands
Your company has hired five new developers who need access to the development server.
- You need to create user accounts for them and add them to a group called
developers
. - Ensure they have read and execute permissions for
/var/www/project
, but cannot modify files. - Restrict SSH access for two users (
User1
andUser2
), allowing only local logins.
- Create the "developers" group
sudo groupadd developers
- Create five user accounts and assign them to the "developers" group
Run the following script to automate the process:#!/bin/bash for user in User1 User2 User3 User4 User5; do echo "Creating user: $user" sudo useradd -m -g developers "$user" # Create user and assign to group echo "Setting password for: $user" sudo passwd "$user" # Prompt to set password done
-m
creates a home directory for each user.-g developers
assigns them to thedevelopers
group.
- Create the project directory
sudo mkdir -p /var/www/project
- Change ownership so "developers" can access it
sudo chown root:developers /var/www/project
- Set permissions
sudo chmod 750 /var/www/project
7
(Owner - root): Read, Write, Execute5
(Group - developers): Read & Execute (no write access)0
(Others): No permissions
- Check permissions
sudo ls -ld /var/www/project
d
(directory)rwx
(Owner's permissions): Read, Write and Executer-x
(Group's permissions): Read and Execute (no write permissions)0
(Others): No permissions
- Ensure OpenSSH Server is installed
If not installed:
dpkg -l | grep openssh-server
sudo apt update && sudo apt install openssh-server
- Deny SSH login for
User1
andUser2
echo "DenyUsers User1 User2" | sudo tee -a /etc/ssh/sshd_config
- Restart SSH service to apply changes
This applies the new settings.
sudo systemctl restart ssh
Your team has reported server slowness during peak hours. Your goal is to:
- Identify the top resource-consuming processes.
- Check disk usage, ensuring logs are not consuming excessive space.
- Monitor real-time system logs for anomalies.
-
Run top command:
top
- Press Shift + P to sort by CPU usage.
- Press Shift + M to sort by Memory usage.
-
If an unnecessary process is consuming resources, terminate it:
sudo kill -9 <PID>
(Replace
<PID>
with the actual process ID)
- Check overall disk space
df -h
- Check logs directory size
du -sh /var/log
- Find the largest log files
(The -5 flag returns the first five largest log files. You can replace 5 with the number of log files you want to see.)
du -ah /var/log | sort -rh | head -5
sudo journalctl -f
- This streams live system logs, helping to detect unusual activities, errors or anomalies.
The development team needs an Nginx web server for a new microservice. You need to:
- Install and enable Nginx.
- Ensure it starts on boot.
- Verify if it is running.
- Restart it when necessary.
sudo apt update
sudo apt install nginx
- Enable Nginx to start on boot
sudo systemctl enable nginx
- Check if Nginx is running
sudo systemctl status nginx
sudo systemctl restart nginx
Security is a top priority at HypotheticalCorp. Your task is to:
- Block all incoming traffic except SSH (22) and HTTP (80).
- Check which ports are currently open.
- Set up SSH key-based authentication.
- Ensure UFW is installed
sudo apt update && sudo apt install ufw
- Allow SSH (Port 22)
sudo ufw allow 22/tcp
- Allow HTTP (Port 80)
sudo ufw allow 80/tcp
- Deny all other incoming traffic
sudo ufw default deny incoming
- Enable the firewall
sudo ufw enable
- Verify firewall status
sudo ufw status verbose
sudo ss -tulnp
-t
(TCP),-u
(UDP),-l
(Listening ports),-n
(Numeric format),-p
(Processes using ports)
- Generate an SSH Key Pair
ssh-keygen -t rsa -b 4096 -C "[email protected]"
- Copy the SSH Key to the Server
(You can generate your local server ip by running the 'hostname -I' command.)
ssh-copy-id username@your-server-ip
-
Disable Password Login for SSH
sudo nano /etc/ssh/ssh_config
-
Restart SSH service
sudo systemctl restart ssh
This guide covers step-by-step instructions to manage users, monitor system performance, set up a web server, and enhance security on a Linux system, in an easy-to-follow manner.