Last active
June 15, 2022 21:23
-
-
Save quiver/b3e750f8c0aaa3f8bb2ab7d485c29cb8 to your computer and use it in GitHub Desktop.
Revisions
-
quiver revised this gist
Jul 3, 2019 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,11 @@ public_key=${tmpfile}.pub private_key=$tmpfile # register public key aws ec2-instance-connect send-ssh-public-key \ --instance-id $instance_id \ --instance-os-user ec2-user \ --ssh-public-key file://$public_key \ --availability-zone $availability_zone # ssh into ec2 instance with private key ssh -i $private_key ec2-user@$ip_address -
quiver created this gist
Jul 3, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ #!/bin/bash # simple shell script to demonstrate how EC2 Instance Connect CLI is implemented. # https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstances.html # # Usage # $ bash eic-cli.sh i-1234 if [ $# -ne 1 ]; then echo "Usage" echo "$ bash eic-cli.sh i-1234" exit 1 fi instance_id=$1 # get EC2 data availability_zone=$(aws ec2 describe-instances --instance-ids $instance_id | jq -r .Reservations[0].Instances[0].Placement.AvailabilityZone) ip_address=$(aws ec2 describe-instances --instance-ids $instance_id | jq -r .Reservations[0].Instances[0].PublicIpAddress) # generate RSA key pair tmpfile=$(mktemp /tmp/ssh.XXXXXX) ssh-keygen -C "eic temp key" -q -f $tmpfile -t rsa -b 2048 -N "" public_key=${tmpfile}.pub private_key=$tmpfile # register public key aws ec2-instance-connect send-ssh-public-key --instance-id $instance_id --instance-os-user ec2-user --ssh-public-key file://$public_key --availability-zone $availability_zone # ssh into ec2 instance with private key ssh -i $private_key ec2-user@$ip_address