Security in Linux
Linux powers servers, cloud platforms, and embedded systems worldwide, making it a prime target for attackers. Security is not a one-time setup - it is a continuous process of hardening, monitoring, and adapting.
To protect the kingdom, administrators must build strong defenses: firewalls, secure authentication, intrusion prevention, and vigilant monitoring.
Principles of Security
The principles of security ensure that Linux systems remain resilient against all kinds of threats.
| # | Principle | Technical Focus | Example Tools |
|---|---|---|---|
| 1 | Encryption | Protects data in transit from eavesdropping | SSH, TLS |
| 2 | Authentication | Ensures only authorized users connect | SSH keys, MFA |
| 3 | Access Control | Restrict who can log in and from where | sshd_config, firewalls |
| 4 | Least Privilege | Avoid root login, use sudo |
User accounts with limited rights |
| 5 | Monitoring & Logging | Detect suspicious activity | auditd, syslog |
| 6 | Regular Updates | Patch vulnerabilities | Package managers (apt, yum) |
Security Principles Rocks
- Linux is widely used in servers, cloud, and embedded systems, making it a prime target for attackers.
- Following these principles ensures resilience against both external and internal threats.
- Security is not a one-time setup - it’s a continuous process of hardening, monitoring, and adapting.
User Privileges and Sudo
- Root User: Supreme wizard with unlimited powers
- Sudo: A royal seal granting temporary authority
- Avoid logging in as root directly; use
sudofor specific tasks
sudo apt update
sudo is the royal seal, granting temporary authority when needed.Firewalls: Gaurding Walls
- A firewall is a set of rules that determine which network traffic is allowed or blocked.
- In Linux, the firewall is built into the kernel’s netfilter framework, and administrators configure it using tools like iptables, nftables, or firewalld.
- It ensures that only trusted connections reach your system while blocking suspicious or harmful traffic.
| # | Tool | Description |
|---|---|---|
| 1 | iptables | Traditional command-line utility for configuring firewall rules |
| 2 | nftables | Modern replacement for iptables, offering better performance and simpler syntax |
| 3 | firewalld | Higher-level service that manages firewall rules dynamically, often used in Red Hat-based systems |
| 4 | UFW (Uncomplicated Firewall) | User-friendly interface for managing firewall rules, common in Ubuntu |
| # | Rule Type | Purpose | Example |
|---|---|---|---|
| 1 | Allow | Permit specific traffic | Allow SSH on port 22 |
| 2 | Deny/Drop | Block unwanted traffic | Block all incoming except HTTP/HTTPS |
| 3 | Forwarding | Redirect traffic | Forward port 80 to 8080 |
| 4 | Logging | Record activity | Log dropped packets for auditing |
sudo ufw enable
sudo ufw allow 22/tcp
sudo ufw status
Enable SSH Port 22 on Linux with UFW
Hackers Firewall Rocks
| # | Principle | Description |
|---|---|---|
| 1 | Principle of Least Privilege | Only open the ports you truly need |
| 2 | Regular Rule Review | Audit firewall rules to remove outdated ones |
| 3 | Logging & Monitoring | Track suspicious activity with tools like auditd or syslog |
| 4 | Defense in Depth | Combine firewall rules with intrusion detection systems and encryption |
Best Practices for Hardening
| # | Practice | Description |
|---|---|---|
| 1 | Disable Root Login | Use non-root accounts with sudo for elevated privileges |
| 2 | Use SSH Keys | Replace passwords with key-based authentication for stronger security |
| 3 | Restrict Access with Firewalls | Control connections using iptables, nftables, or ufw |
| 4 | Enable fail2ban | Block repeated failed login attempts to prevent brute-force attacks |
| 5 | Keep Software Updated | Patch vulnerabilities by regularly updating packages and the kernel |
| 6 | Monitor Logs | Detect unauthorized access attempts using auditd or syslog |
# Monitor logs for suspicious activity
tail -f /var/log/auth.log
# Regularly update packages
sudo apt upgrade
Practical Exercises
- Generate SSH keys and connect securely.
- Disable root login in
/etc/ssh/sshd_config. - Monitor logs for failed login attempts.
- Install Fail2Ban and configure it to block repeated attackers.
Enable UFW and allow only SSH:
sudo ufw enable
sudo ufw allow 22/tcp
Hackers Quest - Mini Project
Fortify a Linux Fortress:
- Set up SSH keys for secure login
- Configure UFW to allow only SSH and HTTP
- Disable root login
- Install Fail2Ban to block repeated attackers
- Document the fortress design in your spellbook
Hackers Notebook
A kingdom without walls is doomed. Security is not optional - it is the shield of your system. Build your fortress wisely, and you will sleep peacefully knowing your kingdom stands strong against invaders.
