Follow these steps:
- Make sure you have VSCode installed.
- Make sure you have a running SSH server preferrable an Ubuntu VM running on an EC2 instance.
- An SSH Client on your local machine.
Steps to SSH on VSCode
- Install the Remote extension pack on your VSCode.
- In VSCode, press F1 to open the command palette, and type connect.
- Select Remote-SSH: Connect to Host. This will bring out options for you to add or configure SSH Hosts.
- Select configure SSH Hosts. This will give you options to create a config file. By default you can choose
/Users/username/.ssh/config. This will open a new file for you were you can create an
- The Host is any name you want VSCode to use to recognize your file.
- The HostName is the public DNS of your EC2 instance or public IP address of your server.
- The User is the username of your server.
- The IdentityFile is the path to your
sshkey which you got when you created your EC2 instance.
Press F1 again to open the command palette. Select Remote-SSH and this time, you should see the Host you just created.
Select yours, and it will attempt connecting to it. When it has successfully connected, you will see SSH connected in the bottom left corner of your VSCode.
Congrats! You have successfully connected your remote server to VSCode. Now you can start working on those files you want.
Port Forwarding instructions
You can add port forwarding rule via
First list all the rules currently running on the NAT (Network Address Translation) table:
[ec2-user@ip-XX-XXX-XX-X ~]$ sudo iptables -t nat -LChain INPUT (policy ACCEPT)target prot opt source destinationChain FORWARD (policy ACCEPT)target prot opt source destinationChain OUTPUT (policy ACCEPT)target prot opt source destination
We don't see anything because we are yet to add a rule forwarding packets sent to external port 80 to internal port 8000 (taking an example here; change it as per your convenience).
[ec2-user@ip-XX-XXX-XX-X ~]$ sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8000
List it again and you will see a new PREROUTING chain:
[ec2-user@ip-XX-XXX-XX-X ~]$ sudo iptables -t nat -LChain PREROUTING (policy ACCEPT)target prot opt source destinationREDIRECT tcp -- anywhere anywhere tcp dpt:http redir ports 8000
You will see the application that was running on port 8000 was responding on port 80 as well.
Whitelist IP on AWS
To whitelist an IP on AWS, all you have to do is follow these simple steps:
- Click the dropdown “Services” from the top-right menu.
- Find the “EC2” service section.
- Click the “Security Groups” option located in the left menu.
- Click “Create Security Group”
- Here, you’ll set the information and rules for the group.
- Click “Add Rule” in the “Inbound” tab.
- Next, set “Type” under “All Traffic”, “Source” under “Custom” and the host/IP address for whitelisting in the text box.
- Once you have added a description, click “Create”.
- From the “EC2 Dashboard”, click “Running Instances”.
- Select the instance for which you want the rule to run.
- Click the dropdown “Actions”.
- Go to “Networking” and click “Change Security Groups”.
- Select the security group you have created
- Click “Assign Security Group”.