Skip to content

Instantly share code, notes, and snippets.

@LozanoMatheus
Last active December 11, 2020 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LozanoMatheus/08c4155beeb56dc4ab2378816858ef99 to your computer and use it in GitHub Desktop.
Save LozanoMatheus/08c4155beeb56dc4ab2378816858ef99 to your computer and use it in GitHub Desktop.
Accessing an EC2 via SSH using AWS SSM
## A basic set up of ~/.ssh/config in your local machine/client
## ssh i-0a1b2c3d4e5f6g7h8i9
Host i-*
User ec2-user
ProxyCommand bash -c "aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p'"
IdentityFile ~/.aws/test-mlozano001.pem
## In this case, it will search for a running instance that has the Tag:Name set to example-ssh-via-aws-ssm
## ssh example-ssh-via-aws-ssm
Host example-ssh-via-aws-ssm
User ec2-user
ProxyCommand bash -c "aws ssm start-session --target $(aws ec2 describe-instances --filters "Name=instance-state-name,Values=running" "Name=tag:Name,Values=example-ssh-via-aws-ssm" | jq -r '.Reservations[].Instances[].InstanceId') --document-name AWS-StartSSHSession --parameters 'portNumber=%p'"
IdentityFile ~/.aws/test-mlozano001.pem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment