Hello Learners…
Welcome to the blog…
Table Of Contents
- Introduction
- Connect AWS EC2 Instance With VSCode Using SSH And PEM Key
- Set Up PEM Key For SSH Client
- VSCode Set Up For SSH Client
- Connect AWS EC2 Instance With VSCode Using SSH And PEM Key
- Summary
- References
Introduction
In this post, we discuss how to Connect AWS EC2 Instance With VSCode Using SSH And PEM Key. Here we go to step by step process of When we have a .pem file and we want to connect our AWS EC2 instance in our VSCode using SSH and .pem key pair.
To learn how to create AWS EC2 instances and download the .pem key pair file please refer to this,
As the cloud computing landscape continues to evolve, mastering the art of connecting AWS EC2 instances to VSCode with SSH and PEM keys becomes an invaluable skill. With this knowledge, developers can harness the full potential of AWS services with their best code editor which is VSCode.
Note:
- To connect the AWS EC2 instance, The EC2 instance is in a running state, and also we have a .pem key file in our local system which is associated with our AWS EC2 instance.
Connect AWS EC2 Instance With VSCode Using SSH And PEM Key
There are many ways to connect AWS EC2 instances and use them for the development and deployment process.
Simple ways to use AWS EC2 instances are with our and directly develop and deploy APIs or do programming in our AWS EC2 instance.
Set Up PEM Key For SSH Client
First, we have to set up our .pem key so that we can use it with the SSH client.
NOTE: change the permission of the .pem file using below command
sudo hmod 400 test_demo.pem
We Go to the directory where the .pem file is located from our terminal and run the below command.
cp test_demo.pem /Users/galaxy_of_ai/.ssh
Change the path of .ssh based on your system. It will copy our .pem file into the .ssh directory.
VSCode Set Up For SSH Client
We hope you have already installed VSCode in your system, You can download it if you don’t have VSCode in your system.
Now we have o install the Remote – SSH client extension in our VSCode. This extension is developed by Microsoft. So install it first.
Connect AWS EC2 Instances From VSCode With SSH Client
After the successful extension installation, we can see the remote ssh extension on the left side, click on it and then click on the “+” button.
To connect with the AWS EC2 instance we required a Public IP address for our EC2 instance.
We can copy it from our AWS EC2 instance dashboard.
After that put the below SSH Connection command in vscode as shown in the below image.
ssh ec2-user@34.238.246.10
In this ec2-ser is the username of our AWS EC2 instance and 34.238.246.10 is the public IP address.
You can change this variable based on your details.
Note: Public IP address is changed every time when we stop and start the AWS EC2 instance.
Now click enter and we can see below, in this select /Users/galaxy_of_ai/.ssh/config where our ssh config files are stored.
After that, we can see the Open Config button, click on this.
In this, we have to add our AWS EC2 instances details, Based on your details change the variable’s values and path of the .pem file.
Host 34.238.246.10
HostName 34.238.246.10
User ec2-user
IdentityFile "/Users/galaxy_of_ai/.ssh/test_demo.pem"
Save the config file. and refresh the remote and we can see our AWS EC2 instance is added successfully.
Now click on the IP address and then on the Connect into new windows…
Then Click on Open Folder…
And we will see the files and directories of our AWS EC2 instances, we have to select the path that we want to open in our VSCode. and click OK.
Hurrah… we successfully connected our AWS EC2 instance to our VSCode.
Now, we can create and delete files or directories from here.
So this is the simple way to use our AWS EC2 instances from our VSCode. And Every DevOps, Cloud Engineer, or MLOps engineer should know about this. so they can use it very effectively.
Summary
Throughout this guide, we have explored the step-by-step process of setting up the connection, emphasizing the importance of securely managing PEM keys and adopting best practices for authentication. By doing so, users can ensure a robust and reliable connection, safeguarding their data and resources in the cloud.
For more learning about the cloud,
Happy Learning And Keep Learning…
Thank You…
1 thought on “Connect AWS EC2 Instance With VSCode Using SSH And PEM Key”