I don’t see how I could put them in .ssh/config? Lets say I have three hosts, with instance IDs i-0abcdabcd, i-1abcdabcd, and i-2abcdabcd. I start them with commands like start_ec2 0, start_ec2 1 etc where start_ec2 knows my alias-to-instance ID mapping and does aws --profile sb ec2 start-instances --instance-ids <alias>. Then to ssh in I have commands like ssh_ec2 0 which looks up the hostname for the instance and then ssh’s to it.
I think Dagon is saying that any time you’re doing ssh -o "OptionKey=OptionValue" you can instead add OptionKey OptionValue under that host in your .ssh/config, which in this case might look like
If I only ever ssh’d into a single EC2 instance (aws-ec2-compute) then that would work, but I have several. Since Host ec2-*.compute-1.amazonaws.com matches any EC2 instance, and there’s no way to tell from the hostname whether this is the one I’m calling ec2_0, ec2_1, ec2_2 etc, I can’t do this through the .ssh/config.
and leave ssh_ec2nf as doing ssh -o "StrictHostKeyChecking=yes" -o "HostKeyAlias=ec2nf" "$ADDR" while still having git, scp, etc work with $ADDR. If “I want to connect to these instances in an ad-hoc manner not already covered by my shell scripts” is a problem you ever run into. I kind of doubt it is, I was mainly responding to the “I don’t see how” part of your comment rather than claiming that doing so would be useful.
I don’t see how I could put them in
.ssh/config? Lets say I have three hosts, with instance IDsi-0abcdabcd,i-1abcdabcd, andi-2abcdabcd. I start them with commands likestart_ec2 0,start_ec2 1etc wherestart_ec2knows my alias-to-instance ID mapping and doesaws --profile sb ec2 start-instances --instance-ids <alias>. Then to ssh in I have commands likessh_ec2 0which looks up the hostname for the instance and then ssh’s to it.I think Dagon is saying that any time you’re doing
ssh -o "OptionKey=OptionValue"you can instead addOptionKey OptionValueunder that host in your.ssh/config, which in this case might look likei.e. you would still need step 1 but not step 2 in the above post.
If I only ever ssh’d into a single EC2 instance (
aws-ec2-compute) then that would work, but I have several. SinceHost ec2-*.compute-1.amazonaws.commatches any EC2 instance, and there’s no way to tell from the hostname whether this is the one I’m callingec2_0,ec2_1,ec2_2etc, I can’t do this through the.ssh/config.If you were to edit
~/.ssh/known_hoststo add an entry for each EC2 host you use, but put them all under the aliasec2, that would work.So your
~/.ssh/known_hostswould look likeThat would mean that host key checking only works to say “is this any one of my ec2 instances” though.
Edit: You could also combine the two approaches, e.g. have
and leave
ssh_ec2nfas doingssh -o "StrictHostKeyChecking=yes" -o "HostKeyAlias=ec2nf" "$ADDR"while still having git, scp, etc work with$ADDR. If “I want to connect to these instances in an ad-hoc manner not already covered by my shell scripts” is a problem you ever run into. I kind of doubt it is, I was mainly responding to the “I don’t see how” part of your comment rather than claiming that doing so would be useful.