×


Steps for creating an EC2 instance and setting up Git remote repository, with detailed descriptions.

Here are the steps to create an EC2(Amazon Elastic Compute Cloud), set up your Git remote repository in EC2 and connect to the remote repo from your local machine. Some explanations are provided for better understanding.

AWS Elastic Compute Service(EC2) is IaaS(Infrastructure as a Service).

 

PART 1 – Creating and connecting to AWS EC2 Virtual Machine instance.

 

STEP 1  – Go to AWS console.

STEP 2 – goto services, click on EC2 and create a virtual machine by clicking on the launch instance button. EC2 is IAAS just like a compute engine in google.

STEP 3 – Amazon has provided templates for engines with different OS and processor combinations. Choose one option and move forward. Select according to your needs and click on launch.

STEP 4 – On clicking the launch button amazon asks to create or choose a  key-value pair. A key pair consists of a public key that AWS stores, and a private key file that you store. You have to provide the private key name. A .pem file with the key will be downloaded which is the private key.

Public-key cryptography, or asymmetric cryptography, is a cryptographic system that uses pairs of keys: public keys which may be disseminated widely, and private keys that are known only to the owner.

 PEM or Privacy Enhanced Mail is a file format for storing and sending cryptographic keys, certificates, and other data.

Upon creation, your instance will be listed in the dashboard with some properties like public DNS an IP.

 

STEP 5 – To connect with the remotely created cloud virtual machine we use a too called putty.

PuTTY is a free and open-source terminal emulator, serial console and network file transfer application. It supports several network protocols, including SCP, SSH, Telnet, login, and raw socket connection.

Secure Shell(SSH) is a cryptographic network protocol for operating network services securely through unsecured networks.

OR

To connect using putty, putty does not accept .pem files. Either we can generate .ppk during the key setting process or we can convert .pem file to .ppk(putty private key ) using puttyGen.

In the session part, provide the Host Name(public DNS) and port.                                                                                          In session – >auth, provide the path to the private key.

 

We also can access the shell of remote virtual machine instance,  using the command line with ssh

 

Note that the file permission of the .pem  file should be 400. This can be achieved using

 

 

Setup a remote Git repository in EC2 Instance

 

STEP 1 – Create a folder in your EC2 instance for your repository after moving into the ec2 instance. Create a repo folder with .git extension, navigate into it.

 

STEP 2 – Initialize a bare git repository using

Bare repositories are usually actual Central remote repositories where every work is moved. It has the actual project. You cannot edit files or directly commit changes to the bare repository. We cannot make changes to a bare repository and changes should not be made to the bare repository as it is the remote central repository. It does not have a working tree.

 

To push to the remote repo on ec2 machine,  you have to add SSH private keys into the SSH authentication agent in your local machine,  for implementing single sign-on with SSH

 

STEP 3 – Now in your local machine, you have to either clone the remote repo or change the config file.

To clone the remote EC2 repo, run the following command.

OR

To create a new project in your local version create a repo with your work

In the .git folder config file, change the remote URL to

ubuntu is the default user name used on EC2 instances with Ubuntu default AMIs.

 

 

You can add origin also using

This command will add something like the following to the config file

 

STEP 4 –Now run the following lines to change configuration and push to remote origin.

Now your local files will be pushed to the remote branch.

Read more from the following links

git receive-pack  – https://git-scm.com/docs/git-receive-pack

EC2 – https://docs.aws.amazon.com/efs/latest/ug/gs-step-one-create-ec2-resources.html

 

 

One Comment

  • ปั้มไลค์ May 16, 2020 at 7:52 am

    Like!! Great article post.Really thank you! Really Cool.

Leave a Reply

Your email address will not be published. Required fields are marked *