Book Image

Fundamentals of Linux

By : Oliver Pelz
Book Image

Fundamentals of Linux

By: Oliver Pelz

Overview of this book

Linux is a Unix-like operating system assembled under the model of free and open source software development and distribution. Fundamentals of Linux will help you learn all the essentials of the Linux command line required to get you started. The book will start by teaching you how to work with virtualization software and install CentOS 7 Linux as a VM. Then, you will get to grips with the workings of various command line operations, such as cursor movement, commands, options, and arguments. As you make your way through the chapters, the book will not only focus on the most essential Linux commands but also give an introduction to Bash shell scripting. Finally, you will explore advanced topics, such as networking and troubleshooting your system, and you will get familiar with the advanced file permissions: ACL, setuid, and setgid. Fundamentals of Linux includes real-world tasks, use cases, and problems that, as a system administrator, you might encounter in your day-to-day activities.
Table of Contents (7 chapters)

Installing VirtualBox and CentOS

In this section, we will show you how to install the free virtualization software called VirtualBox, before creating a new CentOS 7 VM. We will also finish very important post-installation tasks, which we will need to perform in the upcoming sections. Installation of VirtualBox is really straightforward. Executable installers are available for every major operating system. The following are the steps to install VirtualBox:

  1. Open your favorite web browser and navigate to Now, click on the download button that is clearly visible on the home page.
  2. Select a target host OS of your choice. In our example, we will select Windows.
  3. Click on Windows hosts to start the download. Also, don't forget to download the VirtualBox extension pack that you can find on the same Downloads page.

This is a package that will provide better USB support, among other useful features. After the download has finished, open the downloaded installer to run it and install it using the default settings.

Now, let's create a new CentOS 7 VM in VirtualBox. In order to do so, we first need to download the CentOS 7 Minimal ISO file version 1611 from the official CentOS website ( This contains only the most important software packages needed to run a non-graphical Linux server, which is exactly what we want.

The following are the steps for creating a new CentOS 7 VM:

  1. Open a web browser and navigate to Navigate to Get CentOS Now | Minimal ISO.
  2. On the next screen, select the download URL near to your current location for fast download speed. I'm currently located in Germany, so my actual download URL will most likely be different than yours if you're somewhere else.
  1. Wait until the download has finished.
On a modern and fast computer, you can install a fully working operating system such as CentOS 7 inside VirtualBox within a few minutes.
  1. Run VirtualBox on your system. Now, let's reproduce the following steps to install our first CentOS 7 VM:
    1. Click on the New button to create a new VM. If you type the VM Name as CentOS 7, VirtualBox will recognize the two other fields, Type and Version, to be Linux and Red Hat (64-bit) correctly for you.
    2. Click on the Next button to proceed to the next step.
    3. Now, select how much memory or RAM your VM must have. If you don't want any performance issues for your host system, stay in the green area displayed to you in the Memory size window.
    4. For a basic headless server, which means a non-graphical server, at least 2 GB of RAM is recommended. Don't worry, you can change this setting later too.
    5. Click on the Next button and on the next screen leave the default settings as is. Now, click on Create.
    6. Select the VDI option and click on Next. Now, on this screen, stay with the Dynamically allocated option. Click on Next.
    7. On the next screen, double the virtual hard disk size to 16 GB, as 8 GB is way too little for our work.
    8. Finally, click on the Create button to create a fresh and empty VM ready for installation of CentOS 7.

Now, let's install CentOS 7 in our empty VM:

  1. Select our CentOS 7 server VM and click on the green Start button to start it. Here, our downloaded CentOS 7 ISO file will be used as a virtual CD-ROM by VirtualBox and this is where it can be booted or started from.
  2. To do this, click on the small folder symbol and navigate the file browser to your downloaded CentOS 7 Minimal ISO file, and then click on the Start button.
  3. Now, your VM will present you with a text-based start menu, where we will use the up arrow key on the keyboard to select Install CentOS Linux 7 and then press Enter to start the installer.
  1. After waiting for some time, you will be presented with the first graphical installation screen.
Before we click or type something into the VM window for the first time, we need to know how we can switch back to our host system once we are in. If you click once on the guest window, a popup will show up telling you how you can switch controls back and forth.
  1. Select the installer language. In our example, we used the default English language.
This is not the language of your CentOS 7 installation. We will set this type of information on the next screen.
  1. Click on Continue. Now, we are on the main installation screen, where we can customize our installation. You will need to wait until all the items have been loaded.
Here, all the items which are marked with an exclamation mark need to be done before we can proceed with the installation, but you can also do optional settings here like setting your location information.
  1. Next, we need to set the installation destination. Click on INSTALLATION DESTINATION. As we are using an empty VM, we will use the full hard disk for installation, which is the default, so just click on Done which is present at the top-left side of the screen.
  2. Before we start the actual installation, let's quickly enable our Ethernet network card here, so we don't have to do this post installation using the command line. If you are behind a proxy, you can also add this kind of information here in this menu. Click on Done if you're ready.
  3. Now, let's click on Begin Installation. While the installation is ongoing, set a strong and secure password for the administrator or root account, which is the account that has all the rights and control over a system. Click on Done after setting up the strong password.
  4. Now, from the same screen, you can create a normal user account for your everyday work.
The first rule of any secure Linux system is never work with the root user unless you need to.
  1. Click on Done after creating the new user account.
  2. Now wait until the installation has finished. Once the installation is finished, click on the Reboot button to restart your system.
  3. Pressing the Enter key on the start screen will always select and use the latest kernel.
  4. Now, wait until you get a login screen in this window, which is also called our Service Terminal.
  5. Log in using the root user and password you set during the installation.
  6. Then, type the following command in the Terminal and press the Enter key:
# yum update -y    

This command will install all the latest software updates available for your CentOS 7 installation, as the installer media does not have them included.

If you get a new error while this command is running, something must be wrong with your internet connection, so troubleshoot internet connectivity on your host system.

If the core of the CentOS 7 system, which is called the kernel, has been updated, we need to reboot the system. So, type reboot in the Terminal, and then press Enter. After rebooting again, press the Enter key then wait for the login screen to load and log in again.

Next, we type in another two commands, which will clear out all our free space so that we can create a smaller backup image of the system. Now, type the following command with administrative/root access in the Terminal:

dd if=/dev/zero of=/dd.img; rm -f /dd.img    

Now, press the Enter key. This command will override all the free space of your Linux filesystem by creating one big file containing only zeros until the disk is full. This will take some time, so you will need to be patient. If this command outputs some text, it has been finished. You can ignore the error output as this is the expected behavior.

Finally, for setting up SSH port forwarding, we need to write down the actual IP address of our VM's connected network adapter. Run the following command:

ip addr list   

Press Enter and, in the output line type in the IP address, which is the value after the word inet. In our example, it's

To shut down the VM, use the following command and then press the Enter key:

shutdown -h