Tagged CentOS 7

CentOS 7 server VirtualBox tutorial. How to setup and install, part 5.

centos virtualbox horizontal

This is part 5 of the 6 part tutorial series that shows how to install CentOS 7 on VirtualBox.

Part 1 is on the installation and setup of VirtualBox.

Part 2 is on the installation of CentOS 7.

Part 3, part 4 and part 5 is on the configuration of CentOS 7 as well as installation of some nice to have third party software’s.

Part 6 is on general security.


We will continue to use Cmder throughout this tutorial. If you have not gone through the previous tutorials then I suggest you do that first.

We had a very quick look at the firewalld service in the previous tutorial. We made sure that SSH was allowed through port 22. Now we are going to make sure that HTTP, HTTPS and SMTP are also allowed because we will use these protocols and their ports in later tutorials so let us just go ahead and do that first.

We start off by checking if the firewalld service is running in the background.

1

In our case it seems to be running just fine.

Now we are going to add these three protocols that we mentioned.

For HTTP protocol:

For HTTPS protocol:

For SMTP protocol:

2

When you have successfully added them, let us list all allowed protocols just to be sure.

3

As you can see here they are all listed up and that means it is just as we wanted it.

Now what we have to do is to actually save/reload the settings so that they are in use.

4

Now everything about the firewall should be in order for now.


Next up we are going to install “Wget”. What is Wget? To explain it in the simplest way, it is basically what you use to download stuff from the internet with Linux.

The first thing we need to do is to check whether it is installed or not.

5

As we expected. It is not installed. To install Wget we simply run this command:

6

Now that Wget is installed, we can continue installing the rest.


We are now going to enable/install the EPEL repository.

EPEL stands for (Extra Packages for Enterprise Linux). It gives us access to a whole lot of software which I would argue is a must to have.

We use Wget to download the repository.

7

And then we have to install the repository.

8

And it’s that simple. If you want you can verify the repository list.

9

As we can see, the EPEL repository was successfully installed.

If you want to configure the EPEL repo later then you can do so with the file located in /etc/yum.repos.d/epel.repo.


So how do we actually use this EPEL repository? Let’s give an example of how to use it before we move on. Let say that we want a software called “htop” which enables us to monitor our server resources and running processes. We could then try to see if htop was available inside the EPEL repository.

10

As you can see from the picture, it did find a package called “htop”. This means we can install it using the EPEL repository.

11

Now that we have installed htop let us have a look at what it is. Simply run the command “htop”.

You will see a very cool and colorful program that looks like the picture below.

12

As you can see we have overview of the CPU usage, the Mem (memory) usage, and something called Swp which we will come back to later. It simply means “Swap file”, which you can think of as a “reserve backup memory” that is on the hard drive that will be used when the real memory is used up. This is usually used to prevent the server from crashing because of memory shortages.

The rest of the screen shows the running processes. If you hit F5 you will see a tree structure which shows main and sub processes.

13

Click CTRL + C to exit the program.

We will not use too much time on htop on this tutorial. But as you can see it is a very useful program to have. And you also saw how easy it was to install with the EPEL repository.

Now that we have EPEL repository covered, let us move forward.


Next up we are going to install something called “vim”. vim basically is a more “iMproved” vi. It is basically a more improved version of the text editor we are already using on this tutorial. Since that won’t hurt, let us go ahead and install it.

14

After it has completed installation we are going to do something that is very useful in linux, and that is alias.

What this does is that even if we open a file using “vi” it will treat it as “vim”. As the command suggest we just created an alias for “vim”, which is “vi”.

We will be opening files typing “vim” from now on even tho you can use “vi” since it is an alias.


One of the very important things to have in Linux is file compression and archiving.

Gzip and tar is already installed on this version of CentOS. Gzip is used to compress files, and tar is used to organize files into one file so it is very common to see files of the form .tar.gz.

CentOS 7 does not come with regular zip. So we need to install both “zip” and “unzip”.

15

And if we wish to pack files we need “unzip” aswel.

16


This is the end part 5.

In the next and last part of this tutorial series we will look at how to create public
and private keys to improve security. And I will also show you how you can transfer
files to your server in a very secure way using the SFTP protocol.

Click here for part 6.

CentOS 7 server VirtualBox tutorial. How to setup and install, part 4.

centos virtualbox horizontal

This is part 4 of the 5 part tutorial series that shows how to install CentOS 7 on VirtualBox.

Part 1 is on the installation and setup of VirtualBox.

Part 2 is on the installation of CentOS 7.

Part 3 and Part 4 is on the configuration of CentOS 7 as well as installation of some nice to have third party software’s.

Part 5 is on general security.


We are going to start off this part of the tutorial by explaining the benefits of a static ip address. If we choose to set a static IP on the server we have set up, we will be able to do a lot of things. One of those things is to log into the server via an ftp client. This will make working with files much easier.
But probably the most important part of settings a static IP in our case is that we will be able to SSH into the virtual machine. So what is the point with that you may ask. I personally like to work in another command line client with more features like for example “Cmder”, which we are going to use later in this tutorial.

To set up a static ip we will first change into the directory /etc/sysconfig/network-scripts.

Let us list the files:

1

We will be working with the file ifcfg-en0s3 so let us open it up with the vi editor.

Locate the line where it says BOOTPROTO=dhcp. Once you have done that be sure that you are in “INSERT mode”. You can do this by pressing the i button on your keyboard. Now edit that line to BOOTPROTO=static.

Now add these 4 lines of code at the end of the file.

IPADDR=192.168.1.100
GATEWAY=192.168.1.1
NETMASK=255.255.255.0
DNS1=8.8.8.8

Once you have done that press ESC to exit “INSERT MODE” and write “:wq” to write and quit.

2

The IPADDR line is going the virtual machines actual ip address on the network. Most network routers give out the IP address of the form 192.168.1.xxx to the devices on that local are network. I am going to assume that yours do the same, but it could also be something else so be sure to check that out. I chose the IP address of “192.168.1.100” because it does not conflict with any other devices on the network.

Once we have saved the file and existed vi text editor we have to do a network restart.

3

Now let us ping Google DNS servers to see that everything is still working correctly.

4

If you see something like the screen above then it still works and that is great.

To make sure that we have gotten the correct IP address we type in “ip addr”.

5

If you can find the line where it says “inet 192.168.1.100/24” then that means we have the correct IP address.

Let’s do a quick reboot before we go on any further.


We are going to end this part of the tutorial by SSH’ing into the virtual machine from another command line client. But first of all we have to check if there are any firewalls installed on our system and whether or not that firewall is permitting us to SSH into the virtual machine.

The two most common firewall softwares on CentOS is iptables and firewalld. Since we are using CentOS 7 I am assuming that firewalld is already installed and activated on the virtual machine.

To see if firewalld is actviated on our system we can type in this command:

6

Here we can see that the service is clearly up and running. Now let us make sure that iptables is not running.

7

Here we can see that it did not find the service “iptables”. That is great because we do not want both firewall softwares to run simultaneously because that is not a good idea.

Next up we have to make sure that firewalld allows us to SSH into the virtual machine. We can find that out by listing the rules.

8

Here we can see that ssh is among the services that are allowed. That is good. We do not have to change any settings on the firewall for now.


Now we are going to SSH into the virtual machine with a very feature rich command line software called Cmder. If you are on a mac you might not need this but if you are sitting on a Windows operative system like I do then this is pretty much a must.

Go to their official webpage at http://cmder.net/

The website will present you with a screenshot of how Cmder looks like.

9

Scroll down until you reach the download section and click on “Download full”.

10

Once the download is complete extract the contents of the zip file to a place on your desktop as showed in the picture below.

11

Once you have zipped out the contents, make sure that the folder is named “cmder” and that the contents in that folder looks like this with the executable Cmder.exe file.

12

Now copy the “cmder” folder to C:\ as shown in the picture.

13

Now you might delete the cmder folder on your desktop as wel as the cmder.zip file. Be sure to create a shortcut on your desktop that points to Cmder.exe in that folder so that it is easily reachable for later.

14

Now start up Cmder by clicking on that shortcut you just created. A windows like this will pop up.

15

Now comes the moment of truth. We are going to SSH into our virtual machine. Make sure that the virtual machine is running in the background. And type in this command in the cmder command line.

The IP address after “@” must be the ip address of your virtual machine. After you have done
this an output like this will pop up.

16

It will say something like “The authenticity of host ‘192.168.1.100 (192.168.1.100)’ can’t be established. RSA key fingerprint is 49:51:12:8c:4f:74:1b:14:6c:fc:e3:8a:09:ff:50:9a.”

Here you will write “yes” and press ENTER. This will only happen the first time.

It will then say something more and that the “connection was aborted”. Just ignore this and
type in the command to SSH again.

This time it will ask for password of the root user and once you have typed that in successfully you will be logged in to the server.

17

Now Cmder is much easier to work with than the console from VirtualBox. You can copy mulitple lines from the terminal screen by just selecting the lines with the mouse. And you can paste in single lines by pressing Ctrl + V. This will make it much easier to work with the command line as you can easily copy and paste commands.


This is end of part 4. part 5 will continue where we left off.

Click here for part 5.

CentOS 7 server VirtualBox tutorial. How to setup and install, part 3.

centos virtualbox horizontal

This is part 3 of the 6 part tutorial series that shows how to install CentOS 7 on VirtualBox.

Part 1 is on the installation and setup of VirtualBox.

Part 2 is on the installation of CentOS 7.

Part 3, part 4 and part 5 is on the configuration of CentOS 7 as well as installation of some nice to have third party software’s.

Part 6 is on general security.


First thing to do is to login in with “root” by using the password we provided in the previous part of this tutorial. After you have successfully logged in your screen will look the picture below.

1


Press “LeftCTRL + L” to clear the screen.

Let’s check if we have any kind of connection to the internet. Type in the command below and press ENTER.

1.1

Here we can clearly see that the ethernet has a STATE of “disconnected”.

And if we try to ping Google DNS servers using the command:

Then we get the output “connect: Network is unreachable.”


Since there is not that much we can do without internet access we will be fixing that first of all.

Start of by changing directory to this path /etc/sysconfig/network-scripts/.

Now let us list all of the files in this folder.

What we get is something like the picture below.

2

The file that is of any interest for us right now is ifcfg-enp0s3. So let us edit this file by using the vi text editor. Don’t worry if you have not used this text editor before as I will explain how to do everything.

Open up the file using the command below.

3

The first thing to take note of is the last line where it says ONBOOT=no.

We are going to change this to ONBOOT=yes.

Now the way vi text editor works is changing “modes”. Now we are in the “READ mode”. To be able to edit the file we need to be in the “INSERT mode”. To get to “INSERT mode” we simply press the i button on the keyboard.

After you have pressed i on the keyboard you will see the program show — INSERT — on the lower left corner just like you see in the picture below.

4

Now you will be able to freely move the cursor using the arrow keys. Navigate to ONBOOT and replace the “no” with “yes” as shown below.

5

Since you are still in the “INSERT mode” what you need to do now is to press ESC once. The — INSERT — in the lower left corner should have isappeared now. That means you are in the “READ mode”. We are going to try another mode where you are able to write commands to the text editor. Let us
call this mode “COMMAND mode”. You can get to this mode simpy by pressing SHIFT + . which is the same as a colon :. After the colon has appeared in the lower left corner, input “wq” which stands for “write quit”.

6

Press ENTER and the file should now be saved.


Before we can see the effects of the changes we need to do a network restart.

If all went well you should see and output similar to this:

7


Now if we try doing what we did before we will hopefully get another output this time.

Now we have a STATE of “connected”. Which is good.

8

And if we try to ping Google DNS servers again

9

We can see that it works as expected. Press CTRL + C to cancel the pinging.


Now that we have internet access, the first thing we are going to do is update everything.

The -y flag stands for “yes”, so you automatically enter yes for every promt it makes. It not a very big deal but saves us some effort at this point.

This might take a while so just sit back and relax or grab yourself some coffee while waiting.

It will let you know when it has completed the update.

10


Now a good thing to do would be to make sure we have a good hostname.

To change the hostname we need to locate a file called hostname in the /etc folder.

There is not too much in this file at the moment.

Go to “INSERT mode” by pressing i.

Remove the current contents of the file.

Add the line “centos7.local”

Now your screen should look something like this:

11

Since you are still in “INSERT mode”, the — INSERT — still shows up in the lower left corner. Press ESC once and it will disappear. Once it is gone press CTRL + ., or simply write a colon :. And once the colon appears type in “wq”, for “write quit”.

Press ENTER to save the file.

We are going to edit one more file that is located in the same /etc folder.

To make things simple here we just leave the contents of the file as it is, and add a new line to it which is “127.0.0.1    centos7.local”.

Your screen should look something like this:

12

Once you have everything correct just do the same procedure to save on the vi text editor. Go to “COMMAND mode”, input :wq and press ENTER and you are done.

Let’s do a reboot now.


To see if your hostname was successfully changed type in the command

13

If the output is “centos7.localhost” then you know it was a success.


Good job! This is the end of part 3 of this tutorial series.

Click here for part 4.

CentOS 7 server VirtualBox tutorial. How to setup and install, part 2.

centos virtualbox horizontal

This is part 2 of the 6 part tutorial series that shows how to install CentOS 7 on VirtualBox.

Part 1 is on the installation and setup of VirtualBox.

Part 2 is on the installation of CentOS 7.

Part 3, part 4 and part 5 is on the configuration of CentOS 7 as well as installation of some nice to have third party software’s.

Part 6 is on general security.

Let’s get going with part 2!


Now that everything is set from the previous part of this tutorial series, we can just go ahead and start up the virtual machine that we created.

The first thing to pop up will be the CentOS 7 installation screen. Be sure to select the virtual machine’s window so that it can capture your keyboard strokes.

Go ahead and select “Install CentOS 7” with the up and down arrow keys and press enter on your keyboard.

1


In the next screen you will be able to choose your language. I will be leaving it as default as I prefer English as my main language when working with software and tech stuff in general because it is easier to do a Google search when issues occur or when I find some sort of guidelines. Do not worry about the keyboard input language and things like time zones. We will get to that later.

2


What is also important to notice here is that you will be able to use your computers mouse. To use your computers mouse you need to focus click on the virtual machine’s window. Once you have done that a small windows will pop up asking you for confirmation. Just click “Capture”.

If you want you can check the option “Do not show this message again”.

One thing to take note here is that if you want to go outside the virtual machine’s window you have to uncapture the mouse. You do this simply by clicking the right Ctrl button on your keyboard and the mouse will be released from the virtual machine. It’s as easy as that.

3


Now is the time choose correct timezone, time and date settings. Click on the “DATE & TIME” section to be able to select your own timezone.

4


I am going to choose “Europe/Oslo” because my server is located in this timezone. You may select your own timezone if you wish to do so.

After you have selected the correct timezone, make sure that the correct time is set, and that the correct date is set. These can be found in the same screen as shown in the picture below.

Once you are done, click “Done” in the upper left corner of the screen.

5


If you have a keyboard that is something else than a US keyboard, you can change it by  clicking on the
“KEYBOARD” section.

6


Since I own a Norwegian keyboard I’ll have to add that. If you have to do that as well you can click on the plus sign on the down left and choose the correct keyboard layout, which in my case is Norwegian.

You may want to just remove the “English” one so that there won’t be any issues later with mixing things up.

7


Now click on the “INSTALLATION DESTINATION” section.

8


Here we don’t have to do too much. Just make sure that the hard drive is a VBOX HARDDISK and that it shows the correct size that we chose for the virtual machine which in our case was 20 GB.
If everything looks like the picture below then you are good to go. Click “Done”.

9


When all of that is done simply click “Begin Installation” in the lower right corner and we will very soon be done with the installation part of this tutorial.

Don’t worry about the “NETWORK & HOST NAME” part. We will manually change that once the installation is done.

10


Once the installation progress has started you will be presented with two options. You may create a root password while you wait. So I suggest you do that. Click on “ROOT PASSWORD”.

11


Be sure to provde a strong password because if you do not then it will give you a notice that you should have a stronger password, there is no need for you to not have a strong password and it is a good practice to have it so go ahead and write down a strong password and click “Done”
when you are finished.

12


Click the “Finish configuration” button.

13

And then complete the whole process by doing a “Reboot”.

14


When the reboot is finished and the login screen is up, that means we are done with part 2 of this tutorial.

15


Awesome! The next part of this tutorial will go through the configuration of CentOS 7 aswel as installation of some convenient third party softwares.

Click here to continue to Part 3.

CentOS 7 server VirtualBox tutorial. How to setup and install, part 1.

centos virtualbox horizontal

This is a a step by step tutorial on how to setup and install CentOS 7 on VirtualBox. The tutorial consists mainly of 6 parts.

Part 1 is on the installation and setup of VirtualBox.

Part 2 is on the installation of CentOS 7.

Part 3, part 4 and part 5 is on the configuration of CentOS 7 as well as installation of some nice to have third party software’s.

Part 6 is on general security.

So without further ado, let us start with part 1 of this tutorial!


I am going to assume that you do not have VirtualBox installed so let us just go ahead and download it from the official page first.

You can find the download binaries following this url: https://www.virtualbox.org/wiki/Downloads

If you are using Windows then click on the x68/amd64 download url for Windows hosts as you can see in the picture below.

1


After you have downloaded VirtualBox and installed it on your system we now have to download the ISO image file for
the CentOS 7 operating system.

Go ahead to their official download page following this url: https://www.centos.org/download/

Click on the “Everything ISO” button as seen in the picture below.

2


This will take you to a new web page where you can choose from a collection of mirrors to download the ISO image file from. Make sure you have enough space on your hard drive because the file is huge (7 GB).

3


Once the download is complete, and you have successfully installed VirtualBox on your computer, we can then proceed to configure VirtualBox.

First open up VirtualBox. You will see a very plain looking window. Click on “New” to create a virtual machine.

4


You can call your virtual machine whatever you want but I am going to call it “centos7” for the sake of simplicity.

5


Next you are going to have to choose how much RAM you want to allocate. If you can afford it, I suggest you go ahead with 1 GB of ram. 1 GB should be plenty enough for our purpose.

6


Next up you are going to be asked about the hard disk. You do not have to worry about size just yet. You will have the opportunity to choose how much storage you want to add to the virtual machine. For now just let the default settings be, and choose “Create a virtual hard disk now”, and then click “Create”.

7


When the question about hard disk file type appears, choose the default setting of “VDI” and click “Next”.

8


Continue with “Dynamically allocated” hard disk file.

9


And finally we will choose the size of the virtual hard disk. I recommend around 20 GB for Cent OS 7. Finish up the creation of the virtual machine by clicking “Create”.

10


Almost done! Before we go ahead with the installation of CentOS 7 there are still a couple of things we need to do on VirtualBox. First click on settings on the newly created virtual machine.

11


Once you are in the settings window. Choose “Network” and then change the settings of Adapter 1 from “NAT” to “Bridged Adapter”. This way your VM gets an IP address, which is desirable for several reasons.

12


Once that is done. Go to settings again, then “Storage”, then click on “Empty” disc icon under “Controller: IDE” as seen in the picture below. Click on the blue disc that the red arrow points to, and locate the CentOS 7 ISO image file that we downloaded before.

13


And the only thing left now is to click on “Start” to start up the virtual machine.

14


Good job! You have now completed Part 1 of this tutorial series.

Click here to continue to Part 2.