How to Connect EC2 Instance with VSCode Directy using pem file in SFTP

If you want to connect your VS Code to AWS EC2, use the Remote Development extension pack and use it for SSH. The .pem file and the standard SSH config file will reside at:

C:\Users\YourName\.ssh\

Host aws-ec2
     HostName example.dev
     User example
     IdentityFile c:\Users\YourName\.ssh\aws-example-user.pem

I wrote an article detailing the whole VS Code to AWS EC2 setup.


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
}