How to manage a lot of SSH connection information of EC2 instances from ubuntu using different .pem files
Solution 1:
You can try with shortcuts by specify the hostname, username, port, and the private key. Please refer the official docs.
Host MyInstance1
Host example.com or ipaddress
User ubuntu
IdentityFile /path/to/privatekey/MyInstance1.pem
Permission:
chmod 600 ~/.ssh/config
Then Try to access by
ssh MyInstance1
You can also try with aliases :
File:
vi vim ~/.bash_aliases
Then
alias MyInstance1='ssh [email protected] -i /path/to/private-key/MyInstance1.pem'
Solution 2:
An SSH config is great for this, however, upon redeploying new instances the IPs will change and your ssh config will become stale. I wrote a tool that will pull the latest EC2 inventory from AWS and ssh into the system that matches your search: https://github.com/wagoodman/bridgy
bridgy ssh <some-instance-id>
Or if you add a tag called Name
to each instance then you can use that too:
bridgy ssh <some-name-tag-value>
If you have the ~/.aws
creds/config defined as you would with the aws-cli
as well as the following in ~/.bridgy/config.yml
:
inventory:
source: aws
update_at_start: true
ssh:
user: <your ssh user>
...
Then it should work!
One last thing: If you add all of your SSH keys to an ssh-agent
then that will solve your problem regarding multiple key files (all keys are tried against the host you attempt to log into).