Share
As developers, we often work on remove servers via VSCode, which can be challenging if there are multiple hops. The challenge I faced involved connecting to a remote server via an intermediary AWS EC2 instance. Not only I was not able to add breakpoints and debug my code, it also required multiple passwords.
This article details an approach to establish an efficient connection for this jump connection inside VSCode. This guide is intended for developers, sys admins, and anyone looking to enhance their workflow in managing remote servers through VSCode.
My original setup involved a two-step connection process. Initially, I connected to an EC2 instance using a .pem file. A .pem file is a type of file that contains encryption keys or certificates used for secure communications.
ssh -i "path/to/.pem file"
EC2_username@EC2_IP_address
I then accessed the final server by specifying the port (port 9000 in my case) with:
ssh -p 9000 localhost_username@localhost
This method necessitated entering a password multiple times, proving cumbersome and time-consuming.
Direct Access via Modified SSH Command: To enhance efficiency, I modified the SSH command to bypass the intermediary connection, allowing direct access to the remoteserver’s password prompt from Windows PowerShell:
ssh -i “path/to/.pem file” -p 9000
localhost_username@EC2_IP_address
Integrating with VSCode: Utilizing this command within the VSCode Remote-SSH extension, accessed via the Connect to Host option, presented the password prompt directly. However, frequent password entries for each new VSCode folder proved inefficient.
To resolve the issue of repeated password entries, I set up password-less access by utilizing SSH keys. The commands in this subsection were ran in Windows Powershell. The process involved:
ssh-keygen
scp -P 9000 “path/to/.pub file”
localhost_username@EC2_IP_address:~/
cat ~/filename.pub >> ~/.ssh/authorized_keys
rm ~/filename.pub
chmod 600 ~/.ssh/authorized_keys # Read/write by the owner only
chmod 700 ~/.ssh # Owner can read, write, and execute
With the setup complete on the remote server, connecting through VSCode becomes straightforward:
Visual Studio Code Window with Remote Explorer Tab Open
ssh -i “path/to/private key” -p 9000
localhost_username@EC2_IP_address
Here the host name is an IP address. Now you can open files on the remote server.
Ensure good internet connection for both your local machine and the remote server as well as the intermediate server to ensure consistent connection.
This refined approach not only saved time but also enhanced the security of my remote server management operations through VSCode by leveraging SSH keys. By documenting this process, I hope to help others optimize their remote server workflows in VSCode, making them more efficient and secure. Please share any feedback or additional strategies you've found effective in your professional environment!
Incorporate AI ML into your workflows to boost efficiency, accuracy, and productivity. Discover our artificial intelligence services.
View All
© Copyright Fast Code AI 2024. All Rights Reserved