Connect to EC-2 instance using SSH, SSM and VS Code. No public access or ports required

arijusg

Arijus Gilbrantas

Posted on December 22, 2023

Connect to EC-2 instance using SSH, SSM and VS Code. No public access or ports required

Image description

How to

  1. Install SSH extension to vs code.
  2. Import your public Yubikey cert to AWS Key pairs and name it Yubi.
  3. Deploy EC2 with Yubi key attached.
  4. Add the following to ~/.ssh/config:
# This is needed for VS code to know how to connect
Host i-0b377eeb467ae2f92
    HostName i-0b377eeb467ae2f92

# SSH over Session Manager implementation. Change profile as you wish.
Host i-* mi-*
    User ec2-user
    ProxyCommand sh -c "aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p' --profile <<my_aws_profile>> --region eu-central-1"
Enter fullscreen mode Exit fullscreen mode
  1. CMD + Shift + P → Remote-SSH: Connect Current Window to Host…
  2. Select your host and connect.
  3. You can open folder too, for file editing/transfer.
  4. Celebrate!
💖 💪 🙅 🚩
arijusg
Arijus Gilbrantas

Posted on December 22, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related