How To Deploy Code On Aws Ec2 Instance Using SSH On GitLab

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys Welcome to our channel in this session we are going to see how to deploy code on AWS ec2 instance using SSH so let's start so first of all our requirement is we need one ec2 instance we need to put t or Mobile X term to access the ec2 instance and one gitlab account to create dot gitlabs here.tml file and we'll deploy the code on easy to install through this gitlab so let's follow them below steps so first of all let's create one easy to instance one AWS account so let's go to the AWS account and click on the launch instance give the any specific name as a gitlab deployed choose a particular Ami I am selecting Amazon Linux instance type keep tick to dot Micro by default it's a free entire eligible under the key pair if you have you can select otherwise click on the create a new key pair and give the key pair name AWS bitlab and select here dot Pam file click on the create keypad it's downloaded let's scroll down select here hello HTTP traffic from the internet because we will deploy application on HTT HTTP server so by default Port is 80 on or the HTTP protocol so let's scroll down and click on the launch instance okay let's click on view all instance so git tab gitlab underscore deploy it's been pending let's go to the our documentation what is our next step login to ec2 instance using the put t or mobile term and install httpd and give the permission to the slash HTML directory okay so let's launch foreign open the put here give the IP address click on SSH under the auth credentials here we need dot PPK file so we have created AWS underscore with underscore deploy it's a pain file so first of all we need to convert to PPK file so that's the reason go to the foreign file and click on open save as a private key give the name AWS credit lab underscore deploy dot PPK file click on Save close this booktic engine select here put the private key so this is our key AWS underscore gitlab underscore deploy click on open here and click on open just click on accept and give the login username so by default Amazon Linux username is it to hyphen user okay it's the authentication done so first of all we'll move under the root user using the pseudosu command and after that we'll update some packages sudo update hyphen y am update hyphen y it's downloading few latest packages here and after that we'll install HTTP here httpd hyphen y okay after that let's check the status of this httpd sys system still status httpd okay so it's showing inactive let's click on start let's select give the command as a systems it will start http and check status now it's showing active and running okay let's go to our documentation and let's see what is our next step add public IP address private key and username under the gitlab variable okay let's go to the or easy to install so this is our public IP address copy this public IP go to the gitlab project under the CI CD under the variable will store this values here like public IP so AWS underscore public underscore IP I will give the IP address I don't want to protect click on ADD variable let's click on ADD variable give the username AWS underscore username here and give the username so by default username is easy to hyphen user uncheck this one and click on ADD variable okay then after that we need to give the private kws private key so where you will get the private key so we have created them file so we need to copy the content of Beam file Secret underscore key value here and check this one and click on ADD okay so our variable has been added with the public IP address username and a blue secret key then after that uh we need to create a gitlab ci.aml file and use a strict host key checking option with the node because it will if you would like to bypass the verification step you can set this option disable so I had accessing the server it's asking username or password or something we need to do passwordless SSH we need to go inside the slash ATC under the SSH config and we need to disable the password authentication there so here we are using directly the secret key so why this one if we use stricthost key Jain as a no so we can bypass those things directly and we can login to This Server easily so let's go to the Repository and create dot gitlabs here.tml file so let's click on your file give the name so we already defined the file here let's copy this file and paste it here so here we have defined only one stage as a deploy there is a deployed job before the script what will happen here it will create only one SSH file create a DOT SSH directory to store private key and to store our private key here then after that using the Eco key itself copying the content of SSH private key under this SSH direct ID underscore rsf file so just adding the content of private key under the ID underscore rsf file then here we're giving the permission to this ID underscore rsfy So based on this three steps it will help to authenticate our server then after that under the script what we are doing just we are creating One content one sentence You're Welcome to our Channel and we are storing this content inside this index.html file then after that we are using the sap command using the stricthost key checking as a no and we are copying index.html from this current location to this HTML location and Via this variable we have stored under under the variable so we here we are calling easy to username and public IP address so what what username we have here not variables we have given so we'll use here so we have given AWS username using the dollar and AWS underscore public key so let's uh replace those value here and let's clear and let's click on the comment let's go to the pipeline and let's check okay so here we need to give the permission let's go to the code and give the permission as a 777 www.tml and let's retry this one okay so job succeed let's go to this path and let's see 3D slash where www HTML let's check index.html Welcome to our Channel okay let's go to the AWS account copy public IP and let's hit here now the output is showing Welcome to our Channel so our deployment has been done successfully using only this one command we can deploy our application easily so this is a small basic code we have deployed in the coming videos we'll bring lots of things related to Docker kubernetes and terraform so thank you for watching guys please like share and subscribe thank you
Info
Channel: DevOps Z+ Tutorials
Views: 12,128
Rating: undefined out of 5
Keywords:
Id: FfSsGUlOkDY
Channel Id: undefined
Length: 12min 31sec (751 seconds)
Published: Wed Feb 08 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.