Linux Basics For Hackers [Scripting, Networking & More]

Are you getting started on hacking, or are just aspiring for a career in cybersecurity? In either case, you need to familiarize yourself with the full range of ethical hacking tools, and tactics. Most of the hacking tools you will ever come across are meant for use on the Linux operating system (OS). 

As such, you just have to be conversant with Linux, if you are to become a great hacker. You will need to learn everything from the simplest Linux command-line skills to network scanning, scripting to manipulating logging. 

This guide will equip you with the Linux OS basics you need to get started as a hacker. It will teach you such things as how to create, and manage extended file systems on Linux. 

Why Do Most Hackers Use Linux? 

To begin with, almost all cyber security, and hacking tools are written to be run on the Linux operating system. While some hacks may be carried out using Windows, and Mac OS, a good number of the hacking tools you will be using are specifically developed for Linux. 

Additionally, Linux has several other benefits to offer, including: 

Enhanced Granular Control 

The granular design of the Linux OS means that the user has more control over its functionality. With other systems like Windows, you can only change what the developer allows you to. As opposed to this, Linux allows you complete control over everything, through the terminal. 

As a result, you will find scripting on Linux to be simple and effective. 

Exceptional Level of Transparency  

To carry out an effective hack, you need to understand your operating system well, as well as the system you are trying to hack. In this regard, Linux offers you all the transparency you need. This means that you can see and manipulate all aspects of the operating system. 

For comparison, Windows makes it almost impossible for its users to understand its inner workings. With Windows, you never know what is going on beneath the surface. It is such transparency that makes Linux the OS of choice for hackers. 

It is Open Source 

As opposed to most of the leading operating systems, Linux is open-source software. With Linux, you will always have the software source code available to you. Again, this means that you can change, and manipulate the operating system as you please. 

Not only will you be able to understand the inner workings of your operating system,  but you will also be able to alter every component of the Linux OS. The ability to manipulate the OS source code is essential, if you are trying to make the system function in a manner it was not meant to. 

Most Hacking Tools Are Written for Linux

While such tools as Cain, and Abel may be used for hacking on other operating systems, most of the hacking tools are meant for use on Linux. Actually, more than 90% of the hacking tools available today are exclusively written for use on the Linux operating system. 

Then there are those hacking tools that may be used on Linux as well as on Windows, such as Nmap and Metasploit. However, not all the capabilities will be usable, if you happen to use such tools on Windows. This being the case, it only makes sense to stick to Linux for all your hacking attempts. 

Linux Distributions 

The Linux OS may be installed and run directly on a computer just like any other operating system. Alternatively, you may install and run Linux in a virtual machine environment, as discussed later in this guide. The later option allows you to run Linux as a secondary OS on your PC. 

In either case, you will need  to have the appropriate Linux distribution installed on your PC as well. Some of the common distributions you may use include Kali Linux, Parrot OS, Red  Hat, Black Arch, CentOS, BackBox Linux, and Santoku Linux.

While all these distributions share a common Linux Kernel, each has a unique set of utilities, applications, and graphical interfaces As such, each of the distributions looks, and feels a little different from the others. For this guide, you will need to download and install Kali Linux. 


What Will You Need? 

 You need to have the Linux OS installed directly on your PC or through a virtual machine environment. For this guide, you need to install Kali Linux on a Virtual machine, and set them up accordingly. 

This is how you should go about it: 

Download Kali Linux

Kali Linux was specifically designed for use by penetration testers, but comes with an assortment of tools that may be used for other hacking applications. On your browser, navigate to the Kali Linux official download page. Click on the downloads page and select the right OS version for your computer. 

For instance, the Kali  Linux  64  Bit version is a complete suite for 64-bit systems. As a beginner it is advisable to install your Kali Linux on a virtual machine environment. As such, you first need to install the appropriate virtual machine application before proceeding any further.

Installing VirtualBox 

Virtua machine (VM) technology allows the user to run multiple operating systems from the same computer. In this regard, you can continue to run the Windows or Mac OS you are familiar with, and still run a virtual machine ,for Kali Linux. 

There are several virtual machine applications you may use, including Oracle, VMware, and Microsoft. Here is how you can download and install the Oracle’s  free  VirtualBox:

Step 1: Download the VirtualBox

Navigate to the VirtualBox official download page on your browser, click on the Downloads on the left menu to select the right VirtualBox  package. The right package will depend on t  OS you are currently running. Even so, be sure to download the latest version. 

Step 2: Install the VirtualBox 

Once your downloaded has completed, double-click on setup file. This operation will reveal the conventional Setup Wizard. Follow the on-screen prompts to install VirtualBox on your PC. Once the installation is complete, click on the Finish button to close the Wizard window. 

Step 3: Setting Up the Virtual Machine 

The VirtualBox app should launch automatically following successful installation. If it does not launch h, just open it from your desktop. This will display the VirtualBox  Manager window. Now click on the New button on the upper-left corner of the window to open the ‘ Create  Virtual  Machine’ dialog box.

Give the virtual machine a name, or just stick to the Kali name, and then proceed to select Linux from the drop-down menu. Next, you need to expand the third drop-down menu, and select Debian  (64bit), or 32-bit, if you are using the 32-bit Kali Linux version. 

Click Next, and select the amount if RAM you would like to allocate to your new virtual machine. It is advisable to allocate less than 25% of the total system RAM to your virtual machine. Click Next, and select ‘Create Virtual Hard Disk’ on the next screen. 

Once you are done, click on the Create button. 

 Decide on the Hard Disk Allocation

On the screen that appears next, you will be required to choose whether you want the hard disk you just created to be allocated dynamically or at  a  fixed  size. Choose ‘Dynamically allocation  and then click on Next. This means that the system will never take up the entire disk size, unless you need it. 

Thereafter, you need to choose the amount of hard drive space you would like to allocate to the virtual machine as well as the location of the VM. The default allocation is usually 8GBB, but you may need to increase this to between 20 and 25GB. 

Installing Kali Linux on the VirtualBox 

At this point, you will need to install Kali on the VM you just installed. Towards the left of the VM window, you should see an indicator that says that Kali VM is powered off. Click on the Green arrow icon to start it. From the Kali Linux installation files you downloaded, select the file with a .iso extension. 

To do this, you need to click on the Folder icon towards the right side of the window and then navigate to your downloads folder. Select the Kali image file you downloaded earlier, and the click on the Start button. 

Setting up Kali Linux 

Now that you have installed Kali on your Virtual Box VM, you need to customize it to your specific requirements. Following installation, Kali will automatically launch offering you a number of startup choices. As a beginner, it is advisable to use the graphical install option. 

Use the arrow keys on your keyboard to navigate through the menu. If you happen to get an error at this stage, you should enable Virtualization on the system BIOS. Click on the Next button, and select your preferred language. Now click Continue, and select your location. 

Once again, click on Continue and choose your preferred keyboard layout. Click on Continue and allow VirtualBox enough time to detect your hardware and network adapters. Wait until the ‘Network Configuration’ screen comes up before proceeding. 

Configuring the Network for Kali 

On the first configuration screen, you will be required to name the host. The default name is Kali, but you may change it to whichever name you desire, and then click continue. The next screen will require you to enter your preferred password for the root user. 

The root user in Linux is essentially the all-powerful system administrator. Just enter a strong password that you can easily remember. Click on the Continue button and select your current time zone on the screen that comes up next.

Disk Partitioning for Kali

Click continue, and ‘Guided – use entire disk’ on the partition disk screen that comes up. This allows Kali to detect your hard drives, and automatically set up a partitioner. At this point, you will get a warning that all data on the disk you selected will be erased. Just click on the Continue button. 

This won’t cause you to lose any data as you are dealing with a virtual disk that is already empty. On the next screen, select the ‘all files in one partition’ option and then select whether you would like to write the changes to the disk or not.

Finally, select the ‘ Finish partitioning  and  write  changes  to  disk’ option, and click Yes on the confirmation dialog that comes up. Now the system will start installing Kali Linux, allow it enough time to complete the process. Once complete, you will be promoted on whether to use a network mirror, click No. 

Grand  Unified Bootloader (GRUB) Installation 

You will get a prompt enquiring on whether you would like to install GRUB. The bootloader will essentially allow you to select the various operating systems you can boot into. Click on Yes to install the bootloader. On the next screen, select the manual installation option as the automatic one tends to hang at some point. 

Now select the location where you would like to have GRUB installed and click through to the next screen. Once you get the Installation complete screen, you installation of Kali Linux is complete. At this point, you need to click on Continue for the system to reboot. 

After the reboot, you will get the Kali log in screen, just login as root using the password you created. You are now ready to start practicing a few hacking tricks, and techniques. 

Understanding The Linux Filesystem

As you may have realized, the Filesystem structure on Linux is quite different to what you will find on Windows. As opposed to the physical drive structure on Windows (Such as C:  drive), Linux uses a logical filesystem. At the very top of the Linux filesystem is /, commonly referred to as the root of the filesystem. . 

 Branching from the root of the filesystem are several other subdirectories that you need to know, including: 

  • /root – this is the home directory  of  the all-powerful root user 
  • /home – this subdirectory is the user’s home directory 
  • /etc – a directory that contains the configuration files for Linux (the kind of files that control how and when programs start up)
  • /mnt – this is where other Linux filesystems are mounted/attached to the filesystem 
  •  /bin – this directory houses application binaries (equivalent of executable files in Windows).
  • /media – Where CDs and USB devices are  attached/mounted  to  the  filesystem
  • /lib – a subdirectory that contains libraries (shared programs that are similar to Windows DLLs)

Understanding the first level directories on Linux is essential to navigating through the filesystem from the command line. 

NOTE: It is not advisable to log into Linux as root while carrying out routine tasks, such as browsing and running such tools as Wireshark. If someone happens to hack into your system while logged in as root, they will automatically gain root privileges. 

Basic Commands in Linux 

If you are getting started with Linux basics for hackers, you need to understand some of the simplest and most basic commands. Here are some of the basic commands that will get you up and running in Linux: 

Finding  Yourself  with  pwd 

As opposed to graphical  user  interface  (GUI)  environments like MacOS and Windows, the command line in Linux will not always show you the directory you are currently in. In order to successfully navigate to a new directory in Linux, you first need to know the directory you are currently in. 

To do this, you need to apply the present  working  directory (pwd) command. This command returns your location within the directory  structure. To see where you are, just enter pwd in your terminal, as follows: 

kali  >pwd 

/root

In this case, the system will be telling you that you are currently in the root user’s directory /root. If you happen to be on a different directory, the pwd command will return the respective directory name instead. 

Checking  Your Login with whoami 

In Linux, the root is basically the all-powerful super user or system administrator. This administrator has all the system privileges you need to add users, change privileges, and change passwords. Normally, you would not want just anyone to have such privileges. 

As a hacker, you ought to have all the privileges you require to run the desired programs and commands. As a matter of fact, a good number of hacker tools will not work unless you have the root privileges. As such, you will need to log in as root. 

If you happen to have forgotten whether you are logged in as root or user, the whoami command will help you find out. To find out which user you are logged in as: 

kali  >whoami

root 

In this case, the system is telling you that you are logged in as root. If you were logged into Linux as a different user, the whoami command would return the respective username, such as:

kali  >whoami 

OTW

How to Navigate Through the Linux Filesystem 

As a hacker, you just have to learn how to navigate the filesystem from the terminal. If you are to get anything done on Linux, you have the be able to move around, as well as find files, applications, and directories located in other directories. 

As opposed to GUI-based operating systems, you will not be able to visualize the directories in Linux. Instead, the command-line interface in Linux displays a text-based structure. To navigate the Linux system, you need to run different commands. 

Discussed below are some of the Linux navigation commands you need to master: 

Using ls to List Contents of a Directory 

The list (ls) command is used to reveal the contents of a directory, including the files and subdirectories. The ls command in Linux is much like the dir command in Windows. This is how you run the ls command in Linux:

kali  >ls bin        initrd.img              media              boot      initrd.img.old        mnt                dev        lib                     etc        lib64                    opt                proc               home     lost+found               srv             root              run              sbin            var vmlinuz.old vmlinuz.old tmp usr

As you can see, this command lists the files as well as directories contained in the directory you are currently in. Additionally, you may also use the ls command to list the contents of any given directory on your system. 

In such a case, you need to include the directory name after the command. For instance, you could run:

 ls /etc

This command will list the contents of the /etc directory. You can also modify this command to get more details about the files and directories. In this case, you need to add the  -l switch  after  ls to get such details as permissions, size, owner, and when the files were last modified. 

The ls -l will reveal much more information, such as whether an object is a directory or file, the group, number of links, owner and when it was modified. If you would like to list hidden files in Linux, you will need to add a lowercase  –a switch to the command, as follows: 

kali  >ls -la

If you are unable to see the file you expect to see, you should consider using the command with the a flag instead. 

  • Using cd to Change Directories 

The change directory (cd) command may be used to change directories from the terminal. For instance, you may change to the  /etc  directory by entering this command: 

kali  >cd /etc 

[email protected]:/etc#

The promo will change to [email protected]:/etc almost immediately, indicating that you are in the /etc  directory. You can also confirm this by entering the pwd command as follows: 

[email protected]:/etc#  pwd 

/etc

If you would like to move up a single level in the Linux filesystem structure (move towards the root of the file structure /), you should enter the cd command followed by double dots (..), as follows:

[email protected]:/etc#  cd .. 

[email protected]:/# pwd 

/ [email protected]:/#

This operation will move you from the current, /etc directory to the /root directory. You may repeat the command to move up as many levels as you desire. In this case, the number of double dots should be equal to the number of levels you would like to move. 

For instance: 

  • Using  .. will love you a single level upwards
  • Using  .. .. will move you up two levels. 

To move up the structure by two levels, just enter: 

kali  >cd .. ..

Ensure that you leave a space in between each subsequent double dots. 

Getting Help on Linux 

Almost every application, command or utility on Linux has a dedicated help file that offers guidance for its use. To get the help file using aircrackng—one of the best wireless cracking tools, just type in the  aircrack-ng command followed by the –help command, as follows: 

kali  >aircrack-ng –help

Note: The placement of dashes in the command is very specific; double dashes (–) should be used before word options and a single dash (-) before single letter options like -h. Entering the command illustrated above will display a short description of the tool in question, and guidance on its use.

If you happen to require help for nmap (one of the leading postscanning tools), just enter the following command:

kali  >nmap -h

While many Linux applications support all the three help command options  (–help, -h, and  -?), some may fail to work. If any of the commands does not work, just try out another one. 

How to Find Things on Linux 

Working your way around Linux can be quite challenging for a beginner. You will need to master a couple of commands that will help you navigate around Linux with ease. Discussed below are some of the basic commands you will need to find things in Linux: 

  • Using whereis to Find Binaries 

The whereis command will help you find any binary file you are looking for in Linux with much ease. When used effectively, this command will return such information as the location of the binary, its source, and man page if any is available. 

For example: 

kali  >whereis aircrack-ng aircarckng:  /usr/bin/aircarckng  /usr/share/man/man1/aircarckng.1.gz

In this case, the command returned only the aircrackng  binaries  and  man  page, as opposed to every occurrence of the aircrackng word. Many users find this to be more efficient. 

Searching  with locate

This is one of the easiest commands you will ever come across on Linux. The locate command should be entered followed by a keyword denoting whatever you wish to find. The command will CMB through the system to find every single occurrence of the keyword. 

For instance, the following command will search for aircrackng: 

kali  >locate aircrack-ng /usr/bin/aircrackng /usr/share/applications/kaliaircrackng.desktop /usr/share/desktopdirectories/05101aircrackng.directorysnip /var/lib/dpkg/info/aircrackng.mg5sums

The locate command may not be perfect, and often results in overwhelming results with more information than you need. Again, the command uses a database that is usually updated only once a day. 

As a result, files created a few minutes or hours ago may not be detected by the search until the following day. 

Using which to Find Binaries  in  the  PATH Variable

As compared to the locate command, the which command is even more precise. It should be used to find the location of binaries in the PATH variable. Basically, the PATH in Linux holds the directories, in which the operating system searches for the  commands  you  execute on the  command  line

 For instance, entering aircrack-ng on the command  line requires the system to look to the PATH variable to identify the directories it should search for aircrackng. Here it is:

kali  >which aircrack-ng /usr/bin/aircrackng

In this case, the which command was able to find a single binary file within the directories listed in the  PATH variable.  Such directories normally include /usr and /bin, but may include /sbin and /usr as well. 

Final Verdict 

In addition to such basics, beginner hackers also need to learn how to manage running processes and user environment variables. They also should know how to manage and discover wireless networks as well as go anonymous using proxies. 

Before progressing to the more advanced hacking skills like scriptwriting, beginners need to know how the Linux system works. This guide will help you get started with Linux basics for beginners, including how to configure and navigate the system.