How to SSH from one Linux EC2 instance to another

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello all and today we will discuss how to SSH from one Linux ec2 instance to another Before we jump into the demo I have enlisted all the steps as to how we can go about doing this I will strongly recommend that if you are attempting to do this demo or by your own feel free to pause the video over here and follow these steps okay so let's review those steps the first thing that we are going to do is we are going to use putty dot exe to basically SSH to our source Linux ec2 instance using its public IP and on this sorcerer Linux ec2 instance after once we have logged in we will create a new file and copy or AWS key pair that has been used by our target ec2 instance when when I say that we create a file we'll be basically using either one of the editors either nano or wim to create a file and copy the contents of our AWS key pair so the AWS key pair contents that you need to copy is the dot PEM file that is typically generated when you create an AWS key pair for yourself save the AWS key pair file and then finally use a command that's there on the screen essentially to SSH from your source Linux ec2 instance to your target Linux ec2 instance so as you see as a part of this command over here you require the target ec2 instances AWS key pair and its private IP address and eventually you will see that you are connected via SSH to your target Linux ec2 instance ok so let's jump into the demo now so to speed up the demo what I have done is I have launched two ec2 instances over here one is a source instance and other one is a target instance as you can see so let's review to the properties of both these instances so for the source instance as you see we do have a prior a public IP address attached to it now both these instances are actually launched in my default V PC okay and as you see I've associated a public IP SG we will review the properties of this security group shortly the instance type is t2 micro and the key pair that I have used for the source Linux ec2 is WS keep w WAW s key pair sorry okay most of the other properties are the same as default okay now let's review the properties of our target Linux ec2 instance so as you see our target Linux ec2 instance does not have a public IP address it only has a private IP address and this is the IP address that we will use to SSH into this instance from our source Linux ec2 instance it is a t2 micro instance and it is using the same security group we will review the security group shortly and the key pair that it is using is a WX key where the key pair that I have used for both of them at the same you could potentially use a different key pair if you want but the idea or the way to SSH from the source Linux ec2 instance to Target ec2 is each instance will still be the same okay so let's review the security group public IP s3 so as you see this particular security group has port 80 and 20 to inbound open outbound I have kept everything else now even though the ports are open you will be able to ssh into your source linux ec2 instance because it has directly basically using putty because it has a public IP okay well the same thing is not true for your target linux ec2 instance because a target linux ec2 instance does not have a public IP address it only has a private IP address so in order for you to ssh into your target linux ec2 instance is important that you connect to one of your ec2 instances which is publicly exposed and then ssh into this private ec2 instance okay so let's go ahead and copy our IP address of our source ec2 instance so this is the public IP address and we'll copy that we will use putty to connect someone copy the host address over here let me increase the font size so you can easily see okay and then I am going to select my private key this is the private key and click on open so as you see via connected now and we will login over here as ec2 - user ok so we are logged in into our ec2 instance now so the first thing the next thing that we have to do is create a new file so let's use nano ok and all we need to do is we need to copy the contents of our AWS key pair not PEM file over there so let's open up this AWS keep a PEM file in Notepad so as you see I'm opening it up just copy all the contents so ctrl C and paste it right here so we've pasted it all the contents over here exit and you want to say yes and you want to type the name of the key there file so let's give it a name you can give it a WS key fine okay and hit enter okay now remember the name of the file it was a WS key they're fine okay the next thing that we need to do after we have created the AWS key pair file on the source so linux ec2 instance is now used that very same key pair file along with the target ec2 instances private IP address to log in and ssh into it okay so the command for that is essentially this I had a copied this on notepad so that we can continue further ahead easily someone copied over here okay okay until here sometimes if you copy it there you go okay so let's go back and replace these parameters okay so our AWS keep a file name was AWS file and the user that we are going to use is ec2 - user and we have to use the target Linux ec2 instances private IP address so let's go back and copy the IP address so this is our get Linux ec2 instance this is its private IP address let's copy this and paste it here okay so our command is completely ready we as you see the command is ssh - i AWS key pair file name the ec2 user because this is the user that we will be using to connect your target Linux ec2 instance and the target Linux ec2 instances private IP address so let's hit enter so it's asking me whether I want to continue or not someone say yes and now it's telling me the permission is denied and this is because of the permissions on my AWS key pair files I'm going to go ahead and modify those permissions I'm gonna say chmod and make it probably 600 AWS key fine okay so the permissions are modified now now I should go ahead and repeat the same command so hit enter and there you see we are connected to our private ec2 instance this is a target ec2 instance and you can see his IP address right here and now you can go ahead and you know probably try and install something but unfortunately that's not gonna happen here because I don't have an app instance attached so you can probably create let's create a file over here M name I'm gonna go over here create a file this is my target Linux see to these games I'm going to go ahead and save this file so hit escape : WQ and there you go we connected successfully to our target ec2 instance and it's using its private IP and we successfully even created a file on our target ec2 instance okay so let's exit from here type exit and you're back to your original instance which you are here so since Tain's and let's exit from a source instance as well and we are totally disconnected right now okay guys so that's it from me hope you enjoyed this video please feel free to post your comments if you would like me to create videos on any other topic then do let me know otherwise I will see you shortly in some other video thank you and take care bye bye
Info
Channel: NamrataHShah
Views: 27,075
Rating: 4.8220139 out of 5
Keywords: SSH, Linux, EC2, AWS, Key, Private Key, AWS Key Pair, Certification, Associate, How to SSH from one Linux EC2 instance to another, SSH from one Linux EC2 instance to another, one linux ec2 to another
Id: OwptfrdgzDA
Channel Id: undefined
Length: 12min 9sec (729 seconds)
Published: Mon Oct 08 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.