Jul 08

vi Cheatsheet

OVERVIEW

Almost every Linux distribution includes the vi text editor, and it’s usually the only text editor included in minimal installations.  If you’ve never used vi, it can seem really confusing at first and can even be frustrating since you’ll need to use it to configure network settings prior to downloading another text editor such as nano.  If you’re not familiar with vi, it is important to note there is a “command” and “insert” mode. If you’ve never used vi, you’ll probably find it easier at first to enter “insert” mode when modifying a text file, escaping to command mode, and entering the command to save and quit.  Here’s a quick cheat sheet of the commands you’ll need:

Command Definition
i Enters “insert” mode
esc The escape key exits “insert” mode and returns to “command” mode
:wq In command mode this saves the file and quits once you press the enter key
:q! In command mode this quits the file without saving once you press the enter key

EXAMPLE

Open a file to edit with vi

vi /etc/ssh/sshd_config

Once you open the file, you’ll be in command mode by default and you’ll see the line count and character count at the bottom of the file

vi_opened

Now, if you press the ” i “ key you’ll now enter insert mode which is noted at the bottom.  Once in insert mode, you can edit text where the blinking cursor is located just like most other text editors.

vi_insert_mode

Once you’ve finished your modifications, press the Esc key to return to command mode.  In command mode, you’ll see your commands appear at the bottom of the screen when you type them.  Save and quite by pressing the colon key, w key, q key, and press the Enter to execute the commands.

vi_save_quit

Once complete, you’ll see a notification that the file was written.

vi_written

Jul 08

How to Configure Network Settings in CentOS 7

1 – FIND YOUR NETWORK ADAPTER

Once logged in, you’ll want to enable and configure your network adapter.  First, you’ll need to get the name of your network adapter(s) by running the following command:

nmcli d

Below you’ll see my results of running this command.  My results show I have an Ethernet adaptor called ens160 and it’s currently disabled.  Please take note of the name of your network adapter, which may be different.

"nmcli d" Results

2 – CONFIGURE NETWORK ADAPTOR

Once you have the name of your network adapter, you’ll want to enable it and configure it.  We will configure it using the vi text editor.  If you’re not familiar with vi, take a look at:

vi cheat sheet

Use the following command to use vi to configure your network settings.  Note: replace ens160 with the name of your network adapter you noted above)

vi /etc/sysconfig/network-scripts/ifcfg-ens160

The content will look something like this:

TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=ens160
UUID=7f1aff2d-b154-4436-9497-e3a4dedddcef
DEVICE=ens160
ONBOOT=no

To Configure a DHCP IP

Modify the following lines:

BOOTPROTO=dhcp
ONBOOT=yes

To Configure a Static IP

Modify the following line:

BOOTPROTO=static

Add the following lines and replace them with the static IP settings you need.  Note: DOMAIN is the default DNS Search domain and it’s optional to add that line.

IPADDR=192.168.2.11
NETMASK=255.255.255.0
GATEWAY=192.168.2.1
DNS1=8.8.8.8
DNS2=8.8.4.4
DOMAIN=sigkillit.com

3 – CONFIGURE HOST NAME (Optional)

Optionally, you can use vi to configure the host name and default search domain by running:

vi /etc/hostname

Modify the following line:

HOSTNAME=server.sigkillit.com

4 – RESTART NETWORK SERVICE

To apply your new network settings run the following command to restart the network service

systemctl restart network

 

Jul 08

How to Install CentOS 7 Minimal

1 – INSTALL OPERATING SYSTEM

Select Install CentOS 7 and press Enter

Install CentOS 7

Press Enter to begin the installation

Press the Enter Key to begin the installation process

Select your Language and click Continue

CentOS7_Language

Complete any items marked with the Exclamation icon.  Only the Installation Destination should be marked and will be automatic partitioning by default.  Click Installation Destination

CentOS7_Installation_Summary

By default automatic partitioning is selected.  Review the automatic partitioning and confirm it suits your needs and click Done.  Otherwise, you’ll need to manually complete the partitioning (beyond this tutorial).CentOS7_Installation_Destination

Once all the items marked with the exclamation icon are complete, click Begin InstallationCentOS7_Begin_Installation

CentOS 7 will now begin to install.  Click Root Password to set the password while you wait for the installation to finish.

CentOS7_Root_Password_Is_Not_Set

Enter your Root password twice and click Done.  CentOS will rate the strength of your password and obviously the stronger the better.

CentOS7_Root_Password

Once the installation completes, click Reboot.

CentOS7_Complete

The boot menu will automatically boot CentOS 7

CentOS7_Boot_Menu

2 – LOGIN AS ROOT

Once the OS boots, login using username root and the password you set during the installation.CentOS7_Login

3 – CONFIGURE NETWORK ADAPTER

How to Configure Network Settings in CentOS 7

4 – INSTALL VMWARE TOOLS (Optional)

If this installation of CentOS 7 is a VMWare Guest OS, you may wish to install the VMWare Tools by running the following command:

yum -y install open-vm-tools

5 – INSTALL NANO (Optional)

If you are not a fan of the vi text editor, you may wish to install Nano which has a more natural text editor feel to it by running:

yum -y install nano

6 – INSTALL UPDATES

Install updates by running:

yum -y update

7 – CREATE A SUDOER USER

It’s best practice to not use the root (super-user) user account.  Instead, you should always use a regular user account and allow them root privileges by adding them to the sudoers file.  You can then run privileged commands by use the sudo or su commands.  Let’s first start by creating a user by running the following command (where sigkill is the username):

adduser sigkill

Next, we want to set the password for our user by running the following command and enter the password twice when prompted:

passwd sigkill

Here is an example of the output you’ll receive

Add User

Now that your user is created, you want to add them to the sudoers file.  You can edit the sudoers file with vi by running the following command.  (NOTE: If you’re not familiar with vi, take a look at vi cheat sheet)

vi /etc/sudoers

Near the end of the sudoers file, locate the following lines

## Allow root to run any commands anywhere
root	ALL=(ALL)	ALL

Add the following line directly below the above lines then save and quit (:wq)

sigkill	ALL=(ALL)	ALL

Here is an example of how it should look

Sudoers File

8 – PREVENT REMOTE SSH ACCESS FOR ROOT

By default, SSH is installed and ready to work once you configure a network adapter.  Another best practice is to prevent remote SSH access to the root account.

vi /etc/ssh/sshd_config

Locate the following line

#PermitRootLogin yes

Modify the above line to the following then save and quit the file

PermitRootLogin no

Restart the SSH Service by running the following command

systemctl restart sshd