Part 2 



In the Part 1 of this 5-part blog, we had already set up the SSH port in the default security group.

We had also created a key pair which will be used for logging into the ec2 instance.

In this blog we will do the following:

  • Select the appropriate centos-7 ami (Amazon Machine Images). This is the image we will be using for the initial configuration.
  • Select the appropriate ec2 instance type for launching the instance for our initial configuration. For our initial OS configuration, we will be using a “t2.micro”.



Step 1: Install and configure the OS (Centos-7).



    • On the EC2 page

    • On the left tab — Images — AMI catalogue

    • In the AMIs search tab enter — CentOS 7 (x86_64)

    • This will give you multiple options, but we will use the below CentOS 7 “ami” as it’s FREE.



    • Select this AMI. This AMI is Free Tier, which means we will not pay for using this AMI, we will only be paying for the underlying VM that is deployed.

    • Click continue.

    • Next click the “Launch Instance with AMI” (Marked in RED)



This opens the “Launch an instance” page. On this page, there are some important values that need to be specified which are mentioned below:

    • Name and tags

      • Name–> base-os (You can give any name to the EC2 instances you like)
    • Application and OS Images (Amazon Machine Image)

      • AMI from catalog It should pick up the previously selected CentOS-7 image selected earlier.
    • Instance type

      • Instance type –> “t2.micro” ( we will use this for setting up the OS)
      • Key pair (login)–> “jenkins” (use the key-pair created in Step 1: Configuring key-pair
    • Network settings

      • VPC –> use the default settings.
      • Subnet –> No preference (Default)
      • Auto-assign public IP –> Enable
      • Firewall (security groups) –> Select existing security group –> Security groups –> default (Configured with SSH port in Step 2: (Configuring security groups)
    • Configure storage

      • 1 x 10 GiB –> io1
    • Advanced details

      • No configurations are required here.
    • Summary


The summary should look as below. Click the Launch instance once you check your settings. 


Go back to the EC2 page and wait for the instance to be in a running state. In the EC2 dashboard, click on the instance and note down the below public IP address:

We will now log in to the EC2 instance using SSH. In macOS, you can use the terminal shell or any other application for SSH.

In Windows OS, you can use PUTTY or any other application to SSH into the EC2 instance. 

(Important: We are using “jenkins.pem” as this is the key-pair we had specified when creating the EC2 instance)

We use a macOS, so on your local computer, go to the directory where the “jenkins.pem” file was downloaded.


We will be using the default “centos” user to login and perform the initial setup.

    • $ chmod 400 jenkins.pem

(syntax for login = ssh <user>@<aws_public_ip> -i <pem file name>)

    • $ ssh centos@ -i jenkins.pem   

    • Type “yes” at the prompt

This will log into the EC2 instance as user “centos”.


Check your username when you are logged into the EC2 instance, using the below command,

    • $ who am I

centos   pts/0        Feb 27 11:42

We will now create a new user “jenkins” which will be the administrator for the docker and Kubernetes.  We don’t use the default “centos” user  for below reasons:

  • It is a default user and it can be a security risk to use this user.
  • In addition, the “centos” user does not have a password. 



Step 2: Creating a new user for administrating docker & Kubernetes.



The user that installs docker should have a userid of 1000 in CentOS-7 and also have admin permissions. So we will create a new user “jenkins”, assign that a userid of 1000, move the default user “centos” to another userid and then add admin permissions to “jenkins” user. 

In the EC2 instance do the following:

    • sudo su        ### Login as root to create a new user


Create a new user “jenkins” with password: 12345678 (you can provide a strong password for your user)

    • # useradd jenkins     # create user jenkins

    • # passwd jenkins     # create passwd for user jenkins “12345678”

    • # sudo su – jenkins      # login as jenkins user in /home/jenkins

    • $ cd ~

    • $ mkdir .ssh

    • $ chmod 700 .ssh

    • $ cd .ssh

    • $ vi authorized_keys     ## paste the output of ssh-keygen, done in  part1 of the blog.

    • $ chmod 600 authorized_keys


Login as user “centos” to add user “jenkins” to below groups.

    • $ sudo usemod -aG wheel jenkins

    • $ sudo usermod -aG adm jenkins

Exit from the ec2 instance. Now “jenkins” user should be able to login to the ec2 instance.


Login as “jenkins” user to modify the centos users “uid” (User ID) & “gid” (Group ID)from 1000 to 2000.

    • $ sudo usermod -u 2000 centos

    • $ sudo groupmod -g 2000 centos


Exit as “jenkins” user and log in as “centos” user.


Login as “centos” user.

    • $ sudo usermod -u 1000 jenkins

    • $ sudo groupmod -g 1000 jenkinns



Now the “jenkins” user has been added, with userid/groupid = 1000 and centos has been to a different userid/groupid. 

From here on we will do all the installation & configuration, using the “jenkins” user. 



Step 3: Creating an AMI of the base-os



You can take an AMI of this instance and use it for any future CentOS-7 base operations. 

How to create an AMI of an EC2 instance.


Go to EC2 page –> click on the instance –> click the “Actions” tab –> Image and template –> Create image 

This opens a new window. Update the below parameters:

Image name –> centos7-base-image    (give any name that is suitable for you)

Image description –> centos7-base-image  (give any name that is suitable for you)

Click the “Create image” tab





This completes the CENTOS-7 base-os installation.



Part 1 –> Introduction & Pre-requisites

Part 3 –> Installing & Configuring docker on the base os.