Red Teaming

8 min read

Learn Linux (fast): 30 commands for beginners (with cheat sheet)

Want to learn Linux for cybersecurity? This blog post will walk you through the fundamentals of the OS and tips for learning it.

Cry0l1t3 avatar

Cry0l1t3,
Dec 06
2022

Learning Linux operating systems is an essential and inevitable step in cybersecurity. Linux covers about two-thirds of the world's servers, including macOS, which is also based on Linux. Learning it may sound difficult at first, but Linux is simple and only performs the actions we command it to perform.

Once you have it installed in a virtual machine, start looking around. The simple rule to follow when learning anything new, including Linux, is that the more you play with it, the easier it becomes.

An alternative to installing any Linux distribution locally or in the Cloud as a Virtual Private Server (VPS) is to use our Linux system, Pwnbox. Linux is the most stable operating system, and it is tough to harm as a standard user. All you have to do is not delete anything that requires the administrator (in Linux: root) password. Otherwise, feel free to do anything you want with it.

The HTB Academy team has also developed a module called Setting Up to guide you through the installation process. Once installed, pay attention to the following: 

  • What do you see?

  • What do the applications look like?

  • Where can you find these applications?

  • Where are the settings?

(NetworkChuck walks you through the basics of learning Linux for free with HTB)

Free Linux course

Linux fundamentals course: Hack The Box

Master the fundamentals of Linux. Then sharpen your skills with hands-on, browser-based exercises.

Understanding how Linux works

Linux follows five simple principles that make the operating system so durable and efficient:

Linux principles

 

Principle

Description

Everything is a file

All configuration files for the various services running on the Linux operating system are stored in one or more text files.

Small, single-purpose programs 

Linux offers different tools to work with that can be combined in various ways.

Ability to chain programs to perform complex tasks

The integration and combination of different tools enable us to carry out large and complex tasks, such as processing or filtering specific data results.

Avoid captive user interfaces

Linux works mainly within the shell (or terminal), which gives the user greater control over the operating system.

Configuration data is stored in a text file

An example of such a file is the /etc/passwd file, which stores all users registered on the system.

Everything in Linux is a file. All configurations and settings. This means we can find and work with any settings in a text file. However, we can still use the graphical user interface (GUI). Linux only needs a terminal/shell to work with it. Because everything is in single files, we only need to learn a few short commands to work with these files to create, name, move, or customize them.

The other great advantage of Linux is its many different small programs that serve a specific purpose. Experimenting with these tiny tools dramatically increases our power and efficiency in working with Linux. In addition, when we understand the tool's purpose, we can combine this tool with others.

Linux architecture

The Linux architecture is divided into four layers:

Layer

Description

Hardware

Peripheral devices such as the system's RAM, hard drive, CPU, and others.

Kernel

The core of the Linux operating system is to virtualize and control common computer hardware resources like CPU, allocated memory, accessed data, and others. The kernel gives each process its virtual resources and prevents/mitigates conflicts between different processes.

Shell

A command-line interface (CLI) is a shell where a user can enter commands to execute the kernel's functions.

System Utility

Makes all of the operating system's functionality available to the user.

Every computer needs hardware resources to function. It does not matter if it is a tower PC or a laptop. In Linux, the kernel is the core element in software that controls and manages the hardware. The kernel also handles individual processes and prevents them from conflicting.

We input commands into the shell to tell the Linux system what to do; this gives us various system utilities that we can use to control the system.

Linux file system structure

The Linux file system structure is simple. Everything is located in a folder, in which many subfolders are subdivided. Each of these subfolders has a specific purpose. For this purpose, the so-called Filesystem Hierarchy Standard (FHS) was developed.

Linux file structure

At first glance, there seem to be many folders, but after a short time, you will automatically internalize them. Let's take a quick look at the individual descriptions of these folders to understand their purpose:

Path

Description

/

The top-level directory is the root filesystem. It contains all the files required to boot the operating system before other filesystems are mounted, and the necessary files to boot the other filesystems.

/bin

Contains essential command binaries.

/boot

Consists of the static bootloader, kernel executable, and files required to boot the Linux OS.

/dev

Contains device files to facilitate access to every hardware device attached to the system.

/etc

Local system configuration files. These configuration files for the installed applications may also be saved in this directory.

/home

Each user on the system has a subdirectory here for storage.

/lib

Shared library files that are required for system boot.

/media

External removable media devices such as USB drives are mounted here.

/mnt

Temporary mount point for regular filesystems.

/opt

Optional files such as third-party tools can be saved here.

/root

The home directory for the root user.

/sbin

This directory contains executables used for system administration (binary system files).

/tmp

The operating system and many programs use this directory to store temporary files. This directory is generally cleared upon system boot and may be deleted at other times without warning.

/usr

Contains executables, libraries, man files, etc.

/var

This directory contains variable data files such as log files, email in-boxes, web application-related files, cron files, and more.

Now that you understand the structure of the Linux operating system. The next steps are to learn how you can control Linux with different commands.

What is a Linux command?

A Linux command is like an instruction we enter in our terminal to execute a program with a specific purpose. As you can imagine, there are many purposes for different hardware, software, and network components. For example, we can retrieve, create, delete, or edit information. Commands can be divided (but aren’t limited to) the following categories: 

Category

Commands

Retrieve information

ls, cat, less, more, pwd, grep, ifconfig, …

Create or delete information

touch, mkdir, rm, rmdir, …

Edit information

vi, vim, nano, sed, …

Many such commands not only serve a purpose but also offer options that, for example, are not only used to read information but also to edit it. To see what options are available, type "--help" after the command, such as "ls --help".

Linux commands cheat sheet: 30 Linux commands for beginners

The best way to learn Linux for cybersecurity

The best way to learn Linux commands is to get your hands dirty and start practicing in realistic environments. No amount of theory can replace practice. An example of this would be driving a car. How quickly did you learn to drive? 

Most likely, you required multiple driving lessons with an instructor to simply keep up with traffic and master paying attention to many things simultaneously: gears, gas pedals, steering, distances, and traffic signs. Compared to today, you’re probably a more relaxed driver who’s no longer frustrated by the experience; that’s because you’ve already endured the necessary frustration to learn. When trying to learn something quickly (or learning anything at all), remember that: 

The point where you struggle the most is the point at which you learn the most. Encountering feelings of frustration is natural and to be expected.

If you want more detailed guidance on how to master Linux and other cybersecurity concepts, check out the Learning Process module on our Academy.

Linux commands cheat sheet: 30 important commands for beginners

Here’s a list of important commands you will need to quickly work with Linux. Feel free to experiment and play around with them in our browser-based Linux system, Pwnbox. (You can also install Ubuntu or a distribution of your choice in VMware or VirtualBox.)

No.

Command

Description

1

man <tool>

Opens man pages for the specified tool.

2

<tool> -h

Prints the help page of the tool.

3

pwd

Returns working directory name.

4

ls

Lists directory contents.

5

tree

Lists the contents of a directory recursively.

6

cd

Changes the directory.

7

clear

Clears the terminal.

8

touch

Creates an empty file.

9

mkdir

Creates a directory.

10

mv

Move or rename files or directories.

11

cp

Copy files or directories.

12

locate

Uses the locale database to find contents on the system.

13

cat

Concatenate and print files.

14

more

Pager that is used to read STDOUT or files.

15

head

Prints the first ten lines of STDOUT or a file.

16

tail

Prints the last ten lines of STDOUT or a file.

17

whoami

Displays current username.

18

id

Returns users identity.

19

hostname

Sets or prints the name of the current host system.

20

uname

Prints operating system name.

21

ifconfig

The ifconfig utility is used to assign or view an address to a network interface and/or configure network interface parameters.

22

ip

Ip is a utility to show or manipulate routing, network devices, interfaces, and tunnels.

23

netstat

Shows network status.

24

env

Prints environment or sets and executes a command.

25

who

Displays who is logged in.

26

passwd

Changes user password.

27

useradd

Creates a new user or update default new user information.

28

userdel

Deletes a user account and related files.

29

addgroup

Adds a group to the system.

30

delgroup

Removes a group from the system.

 

Author bio: Valentin Dobrykov (Cry0l1t3), Training Development Lead, Hack The Box

Valentin is the Training Development Lead for the Hack The Box Academy. He’s helped create courses like the Linux Fundamentals and OSINT: Corporate Recon modules.

 

Hack The Blog

The latest news and updates, direct from Hack The Box