How to create AWS Keypair using Terraform and attach to EC2 instance | Key to SSH in EC2 server
Вставка
- Опубліковано 19 вер 2024
- Create AWS Keypair with Terraform tool through this tutorial video to SSH in your EC2 instance. In this demo you will 2 ways to create and attach your AWS keypair using Infrastructure as a code tool TERRAFORM!
Terraform Documentation link:
Resource: aws_key_pair: registry.terra...
tls_private_key:
registry.terra...
local_file:
registry.terra...
-----------------------------------------------------------------------------------------------------------------------
#terraform code
resource "aws_instance" "web" {
ami = "ami-00ee4df451840fa9d" #Amazon Linux AMI
instance_type = "t2.micro"
security_groups = [aws_security_group.TF_SG.name]
#first method
key_name = "TF_key"
tags = {
Name = "Terraform Ec2"
}
}
#keypair second method for Key_pair
resource "aws_key_pair" "TF_key" {
key_name = "TF_key"
public_key = tls_private_key.rsa.public_key_openssh
}
resource "tls_private_key" "rsa" {
algorithm = "RSA"
rsa_bits = 4096
}
resource "local_file" "TF-key" {
content = tls_private_key.rsa.private_key_pem
filename = "tfkey"
}
-----------------------------------------------------------------------------------------------------------------------
Learn How to create EC2 instance in Terraform : • How to create Amazon E...
Create security group usingTerraform Tool: • How to Create AWS Secu...
Learn Ansible Tool: • Ansible 101 | Learn An...
AWS SAA C02 Practice Test: • AWS Certified Solution...
------------------------------------------------------------------------------------------------------------------
Connect with me on LinkedIn for notes : / nasiullha-chaudhari-5a...
-----------------------------------------------------------------------------------------------------------------
.
infrastructure as code,keypair terraform,aws terraform,terraform key pair ec2,terraform key pair module,aws keypair cloudformation,create keypair terraform,create ec2 keypair using terraform,aws ec2 keypair with terraform,key pair terraform aws,key pair terraform aws key,terraform aws key_name,resource key pair,ssh key terraform,terraform ssh key,terraform ssh key ec2,ssh ec2 terraform,aws key using terraform,aws ec2 instance using terraform,aws public key,infrastructure as code,keypair terraform,aws terraform,terraform key pair ec2,terraform key pair module,aws keypair cloudformation,create keypair terraform,create ec2 keypair using terraform,aws ec2 keypair with terraform,key pair terraform aws,key pair terraform aws key,terraform aws key_name,resource key pair,ssh key terraform,terraform ssh key,terraform ssh key ec2,ssh ec2 terraform,aws key using terraform,aws ec2 instance using terraform,aws public key,infrastructure as code,keypair terraform,aws terraform,terraform key pair ec2,terraform key pair module,aws keypair cloudformation,create keypair terraform,create ec2 keypair using terraform,aws ec2 keypair with terraform,key pair terraform aws,key pair terraform aws key,terraform aws key_name,resource key pair,ssh key terraform,terraform ssh key,terraform ssh key ec2,ssh ec2 terraform,aws key using terraform,aws ec2 instance using terraform,aws public key,infrastructure as code,keypair terraform,aws terraform,terraform key pair ec2,terraform key pair module,aws keypair cloudformation,create keypair terraform,create ec2 keypair using terraform,aws ec2 keypair with terraform,key pair terraform aws,key pair terraform aws key,terraform aws key_name,resource key pair,ssh key terraform,terraform ssh key,terraform ssh key ec2,ssh ec2 terraform,aws key using terraform,aws ec2 instance using terraform,aws public key,infrastructure as code,keypair terraform,aws terraform,terraform key pair ec2,terraform key pair module,aws keypair cloudformation,create keypair terraform,create ec2 keypair using terraform,aws ec2 keypair with terraform,key pair terraform aws,key pair terraform aws key,terraform aws key_name,resource key pair,ssh key terraform,terraform ssh key,terraform ssh key ec2,ssh ec2 terraform,aws key using terraform,aws ec2 instance using terraform,aws public key,infrastructure as code,keypair terraform,aws terraform,terraform key pair ec2,terraform key pair module,aws keypair cloudformation,create keypair terraform,create ec2 keypair using terraform,aws ec2 keypair with terraform,key pair terraform aws,key pair key,infrastructure as code,keypair terraform,aws terraform,terraform key pair ec2,terraform key pair module,aws keypair cloudformation,create keypair terraform,create ec2 keypair using terraform,aws ec2 keypair with terraform #awsec2
I really Learn a lot from your video on Terraform, you really solved my problem. i would really appreciate if you can make a video on "how to create a VPC using Terraform"
Next Video!! Subscribe and Share :)
Checkout the new video!
He has made an amazing video on creating vpc using terraform 👍
Just wanted to jump in, I was looking for a quick tutorial on this topic, I rarely use ssh keys any longer just ssm and man did this ever hit the spot. Nice simple to the point. Bravo, great tutorial. Good job.
Glad to hear that it helped. Do share and subscribe ☺️
You explain stuff in such an easy manner!!
This video has been immensely helpful in creating my terraform file. Thank you.
Glad to know this helped you! Please consider sharing and subscribing 🙏☺️
You are perfect bro and the way to teach everyone is awesome . Great !! go ahead.
Thank you 😊
Straight to the point! Thank you very much for your videos.
Your welcome 🤗 please subscribe
Hey man! Thanks for your video series.. Amazing.. Short and to the point. Keep up the good work.
Thanks man! Glad you liked it.
Please share and subscribe if you think it was helpful 🙏
Best video on this topic
Excellent Explanation
Glad it was helpful!
I have a question below kindly can you give me a solution
@@cloudchamp I want to copy the public ssh key of the master machine to the ec2 instance created using terraform.
Purpose : - To install jenkins on the ec2 using Ansible. ?
How can i do the same , kindly explain.
You are rocking bro straight to point
Thank You Sandeep :)
Thanks for sharing. need more like this tutorials
Sure !! Happy to help
Very clear explanation
Easiest explanation 👍
Thank You 😊
Thanks you sir for the details you covered in this topic
Happy to help. Share and subscribe for more cloud or devops videos :)
You are genius bro!❤ I was following TechWithNana but i had some doubts in that.. then i saw yours.. you are really good at TF
Thank you avant 🤝
@@cloudchamp one doubt I was doing this project on my windows OS. Out tfkey file got created in the Terraform folder, while accessing the server the error: "key is too open" but I didn't get to change the access of that file. I Googled the equivalent of chmod 400, I got the command "icacls /grant: r" but it didn't work at all. Can u please help?
Hello champ! Thank you for uploading this video!!
Your welcome 🙏 happy to help
Best Video on this topic 🔥🔥
Glad you think so!
Thank you for sharing this champ!!
Perfect !! This is exactly what I wanted
Very Nice buddy short and precise
Thank You. Happy to help !
Best explanation 👍👍👍
Thank you 😊
This helped me today : THANK YOU for you video
You are welcom Azar :) Please subscribe
Very clear explanation brother tq so much for this video done
Thanks 😊 Happy to help👍
Thank you very much.
You are welcome 🤗
Amazing bro!! You're a life saver :)
Thanks 😊
Happy to help
awesome explanation ! kindly help me where we can use nullresources or what's the use of nullresources?
Thanks. Very useful infomation.
Your welcome 🙏
Short and perfect!!
Thank you 😊
Very Good and really useful
Glad to help Madhaiyan :) Do share and subsribe
Thank your for sharing!
Happy to help :)
Thanks, clear explanation!
www.fiverr.com/awscertified/provide-online-training-on-terraform-tool?context_referrer=gig_page&source=other_gigs_by&ref_ctx_id=019524c23995be7949ce87046de7eab5&pckg_id=1&pos=2&seller_online=true&imp_id=525bdb97-34f1-4280-96ee-e987b70d983a
Thank you for sharing this
Your welcome 🙏
Thank you for sharing this 👍👍
Your welcome 🙏
Very helpful!!! thanks, my advise for you is to try to speak a liitle slower, since you speak too fast, however everything looks good.
Thanks for the feedback I will try to improve 👍
awesome bro i subscribed
Thank you Chandra 😁 Means a lot! Happy to help
Hello champion, I used the same command that you have used to connect EC2 instance using SSH , however it says connection refused.... could you please explain me why?
Check if you have the right key and also check if you have port 22 open in your instance security group :)
I want to copy the public ssh key of the master machine to the ec2 instance created using terraform.
Purpose : - To install jenkins on the ec2 using Ansible. ?
How can i do the same , kindly explain.
Wow 😳
Thank you 😊
👍👍👍👍
When I try to ssh using the 2nd method I get a permission denied (publickey,gssapi-keyex,gssapi-with-mic). Any solutions?
I was able to fix it. I just forgot to generate the public key in the ec2 instance
the ssh key created isnt linked to the instance created or me..
Hi , Is it possible to create the key pair without using private ip and with NAT gateway enabled?
🧐 Keypair has nothing to do with private Ip or NAT gateway.
Please provide me more information so that I can help you 👍🏻
Hi , in 1.37 minute you opened one console right.. i dont know how to open that specific console. Kindly help me with this.
That’s my Terminal if you are on windows you can use Git bash or vs code for same
Hey can you please provide the git repo of this project I am havind doubts in provider section
Hi, I tried replicating this, it is requesting for a paraphrase for the key. Could you please explain to me why that happened? Thanks.
You can continue without passphrase, when creating key you get this option?
Your second method is incorrect - it cannot be accessed from outside - locally
Hi, what is the purpose of second method? Is it a security measure?
Both have same security level, the only difference is creating the key pair in the code in the second method whereas in first method we are creating the keypair in the console but attaching it in the code.
can we use YAML instead of JSON in terraform
Terraform neither uses YAML nor JSON but uses similar language called HCL which is Hashicorp configuration Language 👍🏻
I created a video to teach hcl do check out
I tried to implement the second method. and I got a few errors. Is it possible to connect one-on-one?
What error are you getting??
@@cloudchamp I'm unable to login to the EC2.
@@nityadeepika1967 Make sure you have ssh port enabled in security group and keys have right permissions.
I got error while creating keypair
What error did you got ? Send it here , let’s resolve it
Hi
I'm getting the permission denied error. Please can you help?
Make sure your key has 400 permission. You can change the permission with “chmod 400 keyname”
@@cloudchamp please how do I do that with terraform? My protocol is set to -1 to allow both udp tcp connections. I’m also using a MacBook Pro
@@bhengee5172 it’s the key permission issue make sure you add a null resource to change the permission of the key 400 by running above command.
@@bhengee5172 or just open the terminal go to the folder where your key is and run “chmod 400 👍🏻
Not working
after chmod keyname permission denied
same did you get any solution
Use sudo
Very Crispy Short Video
Yeah 😁 but did you understood?
ur not champ ur champion
🙏
@@cloudchamp please do Go language series
It helps
Happy to help! 🤝
i wanted to know whats happening here (tls_private_key.rsa.public_key_openssh) what does public_key_openssh means
👍👍👍👍
🙏