I'm trying to connect EC2 Instance directly from VS Code using SFTP. I can able to connect other ftp service using [password] type, but for EC2 instance i'm having only .pem file. Expecting something like this but using public key .pem file
{
"protocol": "sftp",
"host": "localhost",
"port": 22,
"username": "username",
"remotePath": "/"
}
To connect to your instance using SSH In a terminal window, use the ssh command to connect to the instance. You specify the path and file name of the private key ( . pem ), the user name for your instance, and the public DNS name or IPv6 address for your instance.
Go the folder containing the .pem file of your EC2 instance. Select the .pem file. You can see that the key file is added successfully for your SFTP connection. Finally, Press Ok. In the next step, you’ll connect to EC2 file directory using Filezilla and SFTP.
2) A running SSH server preferrable a linux server running on an EC2 instance. 3) An SSH Client on your local system. a) Install the Remote extension pack on your vscode. b) In VSCode, press F1 to open the command palette, and type connect.
First, Open your Filezilla Client installed in the previous step. Next, Press Edit in the Menu. Press Settings in the sub menu. Next, select SFTP under Connection from the Select Page in the left tab. Next, Press the Add key file button. Go the folder containing the .pem file of your EC2 instance.
You can click “open folder” in the file window and start working like you normally would. And that’s that, you’re ready to edit files on your EC2 instance, in VS Code.
If you want to connect your VS Code to AWS EC2, use the Remote Development extension pack (if it's not installed already). The .pem private key file and the standard SSH config (extensionless text file) will reside at:
C:\Users\YourName\.ssh\aws-example-user.pem
C:\Users\YourName\.ssh\config
Make the latter have contents like this:
Host aws-ec2
HostName example.dev
User example
IdentityFile "C:\Users\YourName\.ssh\aws-example-user.pem"
You can specify nonstandard port by Port 2222
and HostName can be an IP address (on AWS fixed IPs are called elastic). The key file (sometimes extensionless) has the words PRIVATE KEY
in it. New: use the ed25519 type of key if it fails to connect. This is not just for AWS EC2, but any similar system such as Ubuntu in a VM or even a Raspberry Pi.
PS: I wrote an article detailing the whole VS Code to AWS EC2 setup.
Side note: VS Code server needs about 2GB of RAM to run smoothly, if you have less, try zram.
Try this config.json on VScode
{
"remotePath": "/",
"host": "<IP-OR_EC2-INSTANCE-HOST-NAME>",
"username": "USERNAME",
"password": "PASSWORD",
"port": 22,
"secure": true,
"protocol": "sftp",
"uploadOnSave": true,
"passive": false,
"debug": true,
"privateKeyPath": "<PATH-TO-PEM-FILE>",
"passphrase": null,
"ignore": [
------
],
"generatedFiles": {
"uploadOnSave": false,
"extensionsToInclude": [],
"path": ""
}
}
Open the sftp.json config file by pressing ctrl + Shift+ P then type SFTP:Config and edit "host", "privateKeyPath" then save the json file
{
"name": "GIVE ANY NAME",
"host": "ec2-.........compute.amazonaws.com",
"protocol": "sftp",
"port": 22,
"username": "ec2-user",
"privateKeyPath": "SPECIFY YOUR PATH/FILENAME.pem",
"remotePath": "/",
"uploadOnSave": true
}
In my mac OS Catalina 10.15 with Visual Studio 1.39.0 works this, usign a Key Pem:
Note: privateKeyPath, is the path of the key.pem in your computer.
{
"name": "id0000533-test",
"protocol": "sftp",
"host": "ec2-12-123-123-123.eu-west-1.compute.amazonaws.com",
"remotePath": "/var/www/laravel",
"privateKeyPath": "../keypem/id0000533-test.pem",
"username": "admin",
"port": 22,
"secure": true,
"uploadOnSave": true,
"passive": false,
"debug": true,
"ignore": [
"\\.vscode",
"\\.git",
"\\.DS_Store"
],
"generatedFiles": {
"uploadOnSave": true,
"extensionsToInclude": [],
"path": "./"
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With