Last active
November 25, 2020 07:51
-
-
Save redjoker011/8c5ace3059b2b5a755506b9d2924cdf6 to your computer and use it in GitHub Desktop.
Copy Public Key into AWS EC2 Server via AWS CLI ec2-instance-connect
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 characters
#!/bin/bash | |
# Copy ~/.ssh/id_rsa.pub into Host Server | |
# Note: By default it will use `ubuntu` as os user, feel free to change this | |
# | |
# Suppyly instance id and availability zone as script argument | |
# e.g ./copy-pub-key.sh instance-1234 ap-southeast-1 | |
current_dir=pwd | |
instance_id=$1 | |
az=$2 | |
echo "Copying Pub Key into Instance: $instance_id with AZ: $az" | |
cd ~/.ssh | |
aws ec2-instance-connect send-ssh-public-key \ | |
--instance-id $instance_id \ | |
--instance-os-user ubuntu \ | |
--availability-zone $az \ | |
--ssh-public-key file://id_rsa.pub \ | |
--profile cg-manager-ec2 | |
cd $CURRENT_DIR | |
echo "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment