---
title: "Linux World (part II)"
description: "In the previous post, we explored some amazing aspects of Linux. In this post, we’ll apply **system control** and explore some great strategies to protect against attacks."
canonical_url: "https://otabek.io/blogs/linux-world-part-ii"
md_url: "https://otabek.io/blogs/linux-world-part-ii.md"
language: "en"
last_updated: "2024-06-28"
tags: ["Operating System"]
---

# Linux World (part II)

In the [previous post](/blogs/linux-world-part-i), we explored some amazing aspects of Linux. In this post, we’ll dive into **system control** and test out some effective strategies for defending against attacks.

![Meme](https://telegra.ph/file/9051d841d3ae768cd4eff.png)

### System Control

Imagine you’ve made some changes to your system, but to apply those changes, you need to restart it. So, how do you do that? (There’s no power button in a virtual machine! 🙃)

![Tom looking for](https://media1.tenor.com/m/BK_Yx_9yvwYAAAAd/tom-and-jerry-looking-for.gif)

You’ll need the `systemctl` command, which is used to control various system services in Linux. Services are background programs that keep your system running. You can restart, stop, start, disable, or enable these services using **systemctl**.

```bash
# Restart the SSH service
systemctl restart sshd

# Check the status of the service
systemctl status sshd

# Disable the service (prevent it from starting automatically)
systemctl disable sshd
```

If you want to ensure that your program runs continuously in the background, you’ll want to learn about [**systemd**](https://www.suse.com/support/kb/doc/?id=000019672). It’s a simple framework that guarantees your program will keep running in the background thanks to the systemd (system daemon) file.

### Fork Bombing

![Fork bomb cat](https://telegra.ph/file/48abcfa8d77acd6000eef.png)

Back in 2020, I was a first-year student at **Shanghai JiaoTong University**, meeting incredibly smart and talented classmates from all over the world. After some time, I sent one of my friends the image above with a different message. The message was:

> If you run this command, you’ll see a cat image: :(){ :|:& };:

A young, curious student (me at the time) who was just beginning to understand OS concepts tried this on his own computer. Five minutes later, he messaged me saying that his computer shut down by itself 🥲 (well, he was new, and I wasn’t exactly experienced either!).

This command is called a **Fork Bomb**. It recursively creates new processes in the system (in Linux, processes are "forked" from the **main process**, which is why it's called a "fork bomb"). The goal of the command is to rapidly generate processes, leading to resource exhaustion. Too many processes can cause a slowdown, and in some cases, it can even crash your computer. So, how can you prevent this?

![Limits](https://telegra.ph/file/c6dc8df6cfec0fa9c19ee.jpg)

The answer is simple: set limits for your system. You can use the `ulimit` command to limit the number of processes and prevent **fork bombing**. Interesting, right?

```bash
# Check how many processes we can open
ulimit -u

# Get more information
ulimit -a

# Limit the number of processes to 20
ulimit -S -u 20
```

### Disk Space Filler

At [cloud.42.uz](https://cloud.42.uz), we work on various optimization tasks. However, there was this one “jprq” who constantly tried to crash the server using various clever methods. In a way, I’m thankful to him because he taught me a lot (I mean, he forced me to improve security and add more capabilities). His latest attack was the **Disk Space Filler**.

To prevent this kind of attack, we need to install the **quota tool**, which allows us to limit the number of file descriptors and clean up unnecessary files from the disk. I recommend you explore this on your own for better understanding.

### Conclusion

In conclusion, don't believe everything you read or hear. Never run unfamiliar commands on your computer. Stay cautious, stay alert. Share what you've learned from this post with others!

---

```quiz
{
  "quiz": {
    "id": "linux-security-quiz",
    "title": "Linux Security Quiz",
    "description": "Test your understanding of Linux system control and security",
    "questions": [
      {
        "id": "q1",
        "type": "single-choice",
        "question": "What command is used to control system services in Linux?",
        "options": [
          { "id": "a", "text": "systemctl", "description": "" },
          { "id": "b", "text": "servicerun", "description": "The correct command is systemctl, not servicerun." },
          { "id": "c", "text": "sysmanage", "description": "Use systemctl to manage system services." },
          { "id": "d", "text": "processctl", "description": "systemctl is the correct command for service management." }
        ]
      },
      {
        "id": "q2",
        "type": "drag-fill",
        "question": "Complete the command to restart the SSH service:",
        "template": "{{b1}} {{b2}} sshd",
        "options": [
          { "id": "opt1", "content": "systemctl" },
          { "id": "opt2", "content": "restart" }
        ],
        "blanks": [
          { "id": "b1" },
          { "id": "b2" }
        ]
      },
      {
        "id": "q3",
        "type": "single-choice",
        "question": "What is a Fork Bomb?",
        "options": [
          { "id": "a", "text": "A virus that deletes files", "description": "Fork bombs don't delete files - they exhaust system resources." },
          { "id": "b", "text": "A command that recursively creates processes until resources are exhausted", "description": "" },
          { "id": "c", "text": "A tool for splitting files", "description": "Fork bombs are malicious, not file utilities." },
          { "id": "d", "text": "A backup command", "description": "Fork bombs are attacks, not backup tools." }
        ]
      },
      {
        "id": "q4",
        "type": "single-choice",
        "question": "Which command limits the number of processes a user can create?",
        "options": [
          { "id": "a", "text": "ulimit", "description": "" },
          { "id": "b", "text": "proclimit", "description": "The correct command is ulimit." },
          { "id": "c", "text": "maxproc", "description": "Use ulimit to set process limits." },
          { "id": "d", "text": "limituser", "description": "ulimit is the command for setting user limits." }
        ]
      },
      {
        "id": "q5",
        "type": "drag-drop",
        "question": "Arrange the systemctl actions in order: check status, stop, then restart a service:",
        "items": [
          { "id": "status", "content": "systemctl status sshd" },
          { "id": "stop", "content": "systemctl stop sshd" },
          { "id": "restart", "content": "systemctl restart sshd" }
        ]
      },
      {
        "id": "q6",
        "type": "single-choice",
        "question": "What tool can prevent disk space filling attacks?",
        "options": [
          { "id": "a", "text": "quota", "description": "" },
          { "id": "b", "text": "diskwatch", "description": "The quota tool is used to limit disk usage." },
          { "id": "c", "text": "spacelimit", "description": "Use the quota tool for disk space limits." },
          { "id": "d", "text": "fillstop", "description": "The quota tool manages disk space limits." }
        ]
      }
    ]
  },
  "answers": {
    "q1": { "correctOptionIds": ["a"] },
    "q2": { "correctPlacements": { "b1": "opt1", "b2": "opt2" } },
    "q3": { "correctOptionIds": ["b"] },
    "q4": { "correctOptionIds": ["a"] },
    "q5": { "correctOrder": ["status", "stop", "restart"] },
    "q6": { "correctOptionIds": ["a"] }
  }
}
```


## Sitemap

See the full [Markdown sitemap](/sitemap.md) for all pages.
