Launch and setup a free tier AWS EC2 instance with Red Hat Enterprise Linux 8.

In this post I will explain the steps to configure a free tier AWS EC2 instance with Red Hat Enterprise Linux 8 and how to access it through SSH.

1. Create and activate a new Amazon Web Services account.

a. Go to  Amazon Web Services home page

b. Follow the steps explained by Amazon to create and activate a new Amazon Web Services account

2. Launch a new instance

Click on Services > EC2 > Instances > Launch Instance

a. Click on Launch Instance button

b. Select the pre-configured Red Hat Enterprise Linux 8 (HVM) , EBS General Purpose (SDD) Volume Type.

c. Chose the Instance Type

1. Select the type t2.micro (Free for eligible)

2. Click on Next: Configure Instance Details button

d. Configure Instance Details

1. Select Enable in the field Auto-assign Public IP

2.Click on Next: Add Storage button

e.Add Storage

1.Click on Next Add Tags button

f. Add Tags to add additional information associated with the instance.

1.Add the tag SERVER EC2

2. Enter REL 8

3. Click on Next: Configure Security Group.

g.Configure Security group and add access to SSH.

1. Enter Security group name: SECURITY_TO_EC2_POSTGRESQL

2.Select Type: SSH

3.Select Source My IP

4. The public IP will have access to the AWS EC2 instance

5.Click on Review and Launch button.

h. Review Instance Launch and verify your Instance Type, Security group , Instance details and Storage are correct.

1.Click on the Launch button.

i. Create a new key pair

1.Select Create a new key pair

2.Enter a name for the new key pair

3.Download your new key pair file: server_rhelp8.pem in you local filesystem.

4. Click on Launch Instances button.

j. The EC2 instance will be Launched in a few minutes

1. Click on the View Instances button to see the status of the instance.

k. EC2 instance is up and running

1. AWS assigns the IPv4 Public IP : 54 86.185.59 (take in consideration that this IP is not fixed and can change if you restart the instance).

2. The Key Name is the key name created in the step h and is assigned to the instance.

3. The security group SECURITY_TO_EC2_POSTGRESQL added to the EC2 instance allow SSH access from the public IP

AWS generates a PEM file (Privacy-Enhanced Mail), if you want to use Putty to connect through SSH first you have to generate a ppk (Putty Private Key) file.

3. Generate a ppk (Putty Private Key) file.

a. Download and open PuTTYgen from the PuTTY Download Page

b. Run puttygen.exe

1. Click on Load button to load the file server_rhelp8.pem generated in the step h.4.

c. 1.Click on OK button

d.1. Click on Save private key button

2. Click on Yes button if you do not want a passphrase.

e.1 Enter el name of ppk server_rhel8.ppk

2. Click on the Save button

4. Connect to the EC2 instance using SSH Putty.

a. Run putty.exe

1. Host_Name (or IP address): Enter or the
Public DNS (IPv4)

b. Select the Putty private key

1.Click on Connection > SSH > Auth

2.Enter in the field Private key file for authentication the file server_rhel8.ppk from the step 2.d.1

c.Click on yes button

d. In login as: enter the user ec2-user

5. Create a new user dbadmin with administrative / root privileges without need to use the private key.

a. Create a user dbadmin

[ec2-user@ip-172-31-87-123 ~]$ sudo useradd -G wheel dbadmin         
[ec2-user@ip-172-31-87-123 ~]$ id dbadmin
uid=1001(dbadmin) gid=1001(dbadmin) groups=1001(dbadmin),10(wheel)

b. Set a password for the user dbadmin

[ec2-user@ip-172-31-87-123 ~]$ sudo passwd dbadmin
Changing password for user dbadmin.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[ec2-user@ip-172-31-87-123 ~]$

b. Enable password authentication in the SSH configuration file.

[ec2-user@ip-172-31-87-123 ~]$ sudo vi /etc/ssh/sshd_config
PasswordAuthentication yes #<---- Change to yes

c. Restart SSH service.

[ec2-user@ip-172-31-87-123 ~]$ sudo systemctl stop   sshd
[ec2-user@ip-172-31-87-123 ~]$ sudo systemctl start  sshd
[ec2-user@ip-172-31-87-123 ~]$ sudo systemctl status sshd
● sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2020-03-25 19:27:14 UTC; 1min 12s ago
     Docs: man:sshd(8)
 Main PID: 7232 (sshd)
    Tasks: 1 (limit: 4998)
   Memory: 1.1M
   CGroup: /system.slice/sshd.service
           └─7232 /usr/sbin/sshd -D,,aes256-ctr,>

Mar 25 19:27:14 ip-172-31-87-123.ec2.internal systemd[1]: Starting OpenSSH server daemon...
Mar 25 19:27:14 ip-172-31-87-123.ec2.internal sshd[7232]: Server listening on port 22.
Mar 25 19:27:14 ip-172-31-87-123.ec2.internal sshd[7232]: Server listening on :: port 22.
Mar 25 19:27:14 ip-172-31-87-123.ec2.internal systemd[1]: Started OpenSSH server daemon.

6 . Change the hostname to dbserver.

a. Add the new hostname for RHEL server.

[root@ip-172-31-87-123 ~]# hostnamectl set-hostname

[root@ip-172-31-87-123 ~]# hostnamectl
   Static hostname:
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 05181ee533214e98a46221aadb1f71dc
           Boot ID: fd0f341252854faeadc9b0d45c5b3e93
    Virtualization: xen
  Operating System: Red Hat Enterprise Linux 8.0 (Ootpa)
       CPE OS Name: cpe:/o:redhat:enterprise_linux:8.0:GA
            Kernel: Linux 4.18.0-80.4.2.el8_0.x86_64
      Architecture: x86-64
[root@ip-172-31-87-123 ~]#

7. Login as dbadmin without using Putty private key.

a. Enter the public IP.

b. Enter the password created in the step 5.b