This tutorial will show you how to login to your ec2 instance without having to do
ssh ./pem.key firstname.lastname@example.org each time.
With this easy to setup method you can login to any number of ec2 instances with a simple command for each instance. No installs needed!
going from this
ssh ./pem.key email@example.com
(you can name your entry point whatever you'd like)
- The absolute path to your pem file related to the ec2 instance you want to login to.
- The IPv4 address of your ec2 aws instance.
First edit your ssh config file in vscode. To do this type in the following
Something like this should popup
Then you're going to add and fill in some syntax
Hostwill be the shorthand text you type to log into your instance from anywhere in terminal.
HostNameThis you need to get from aws. It's the Public IPv4 address of the instance you want to login to.
UserThis is your instance user. If you created a ubuntu instance keep it as ubuntu.
IdentityFileThis is going to be the location where your pem key resides. Make sure to use an absolute path to your pem key. Here's a good article that describes what the
~key is in this path.
IdentitiesOnlyjust keep it as yes for now. I'll update why soon.
Once all this is filled out then you can now login to your ec2 instance from anywhere! With the example I provided I would just type
ssh api-on-ec2 and I'm in!
I no longer have to type
ssh ./pathToPem.pem firstname.lastname@example.org!
There will be times where your IPv4 address will change such as stopping your ec2 instance. In this case all you have to do is update your
HostName in the ssh config to the new address and you're good to go!
Same goes for your pem file, make sure that if you move it to another location to also update
IdentifyFile pem path in ssh config to reflect the new location.