Skip to content

Instantly share code, notes, and snippets.

@sechiro
Last active August 29, 2015 14:06
Show Gist options
  • Save sechiro/d34d62f77554c7b6698b to your computer and use it in GitHub Desktop.
Save sechiro/d34d62f77554c7b6698b to your computer and use it in GitHub Desktop.
ec2sshぽい何か。VPC内でPrivateDnsNameで接続する用。
aws ec2 describe-instances | jq -r '.Reservations[].Instances[]| (.Tags[] | select(.Key=="Name").Value) + " " + .PrivateDnsName' > /tmp/instance_list
OLDIFS=$IFS
while read line
do
IFS=" "
set -- $line
echo "Host $1
Hostname $2"
done < /tmp/instance_list > /tmp/ssh_config
IFS=$OLDIFS
# ~/.ssh/config の最後に「##### EC2SSH.sh #####」をつけること
sed -i '/^##### EC2SSH.sh #####/q' ~/.ssh/config
cat /tmp/ssh_config >> ~/.ssh/config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment