Linux World (part II)

Jun 28, 2024

Cover image for Linux World (part II)

In the previous post, 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

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

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.

If you want to ensure that your program runs continuously in the background, you’ll want to learn about systemd. 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

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

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?

Disk Space Filler

At 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!