CodeGym /Courses /Docker SELF /Basics of Security in Linux

Basics of Security in Linux

Docker SELF
Level 5 , Lesson 0
Available

Basics of Security in Linux

1. Principles of Security in Linux

Security in Linux is, first and foremost, a "least privilege" strategy and reliable access control. Think of Linux like a fortress with layers of protection: the further you go, the more checks you face. But first, let’s go over the three pillars on which system security stands.

Access Rights Division: Users, Groups, and Root

The secret to Linux's stability and security is strict division of access rights. The system has three types of entities:

  • Users: individual accounts. Think of them like guests at a family party — each with their own entry pass.
  • Groups: sets of users. Sometimes one pass works for the entire group — like accessing a shared "Grandma's Photos" folder.
  • Root: a superuser with all the permissions. Root is like Superman in your Linux world. He can do anything, which comes with both superpower and super responsibility.

Linux uses this model to limit access to files, apps, or system functions. Even if a hacker gets into the system as a regular user, they won’t be able to mess with the kernel or critical files.

Minimizing Privileges

You don’t want to hand out root access to everyone. Imagine if everyone in your office had keys to the money vault. Someone’s bound to lose theirs. In Linux, the rule is: give users only the permissions they need to complete their tasks.

Main Security Threats

  • Viruses: yep, Linux isn’t 100% safe either, but viruses are less common here thanks to the system’s architecture.
  • Network Attacks: SSH hacks, DDoS attacks, DNS spoofing.
  • Software Vulnerabilities: outdated packages and insecure libraries can be entry points for hackers.

2. Threat Prevention

Now let's dive into some important steps to keep your Linux server loyal and trustworthy without turning into a hacker's tool.

Regular System Updates

A real-world example: system updates are like updating your antivirus. Without it, even the most modern protection will be useless against new threats. The command:

sudo apt update && sudo apt upgrade

helps keep your Linux in shape.

Access Control to Important Files

There are files you'd rather keep hidden from prying eyes. For example, the /etc/sudoers file — it's a list of users with access to admin privileges. You should only edit it via visudo to avoid any accidental mistakes.

Limiting Root Access

You know root has power, but don't overdo it. It's better to work as a regular user and use sudo when needed to temporarily gain privileges.


3. Security Tools

What tools in Linux help with security? Let's take a look at built-in and third-party solutions.

Built-in Mechanisms

  • firewalld and iptables: firewalls for managing network traffic. Sounds tricky, but we'll figure it out!
  • SELinux (Security-Enhanced Linux): a special add-on that checks which processes are allowed to access files.
  • ACL (Access Control Lists): an advanced version of standard access rights.

External Tools

  • Lynis: a tool for security audits.
  • OpenSCAP: a set of tools for checking system compliance with security standards.

Password Policy Setup

How strong is your pass... oh, don’t tell me! It's better to ensure a reliable password policy right away. Minimum length and complexity can be set up using PAM.

sudo nano /etc/security/pwquality.conf

Example parameters:

minlen = 12
minclass = 3

4. Practical Example: Basic Security Setup

Alright, roll up your sleeves! Let’s set up a simple security policy for a test system.

User Registration

We’ll create two users: an administrator and a regular user.

sudo adduser admin
sudo adduser user1
sudo usermod -aG sudo admin

Now admin has admin rights, while user1 does not.

Managing Access to Important Files

Let’s restrict access to the Nginx configuration:

sudo chmod 600 /etc/nginx/nginx.conf

Working with the Firewall

We’ll install and configure ufw (Uncomplicated Firewall) to protect our server:

sudo apt install ufw
sudo ufw enable

Allow only SSH and HTTP traffic:

sudo ufw allow 22
sudo ufw allow 80

Enable a status check:

sudo ufw status

5. Common Mistakes

When it comes to security, it's important not just to know what to do but also to understand what to avoid.

Mistake 1: Running as root

A lot of beginners are lazy and use the root account. This is dangerous: any mistake or breach can be fatal for the system.

Mistake 2: Outdated packages

As one admin said: "The only good server is an updated server." Old software is the perfect target for attacks.

Mistake 3: Weak passwords

"password123" is one of the most popular passwords out there. Don't be that person who uses it.


6. Practical Application: Why Do You Need It?

Setting up Linux security will not only help you at work, but also during interviews. Knowing the basics of working with firewalls, SELinux, and access rights configuration impresses employers. For instance, you’ll be able to protect a company’s server from DDoS attacks or configure permissions for team collaboration on projects.

If you’re into development, securing the system means your code won’t leak to competitors, and client data stays safe. This isn’t just some “Khabarovsk paranoia,” but a legit need in today’s industry.

1
Task
Docker SELF, level 5, lesson 0
Locked
Checking the current security status
Checking the current security status
1
Task
Docker SELF, level 5, lesson 0
Locked
Assigning permissions and restrictions
Assigning permissions and restrictions
1
Task
Docker SELF, level 5, lesson 0
Locked
Setting up restricted access
Setting up restricted access
1
Task
Docker SELF, level 5, lesson 0
Locked
Setting up a basic firewall
Setting up a basic firewall
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION