Intro
This tutorial will show you how to login to your ec2 instance without having to do ssh ./pem.key ubuntu@0.00.00.0
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 ubuntu@0.00.00.0
to this
ssh api-one-ec2
(you can name your entry point whatever you'd like)
Tutorial
Things you need
- 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.
Steps
First edit your ssh config file in vscode. To do this type in the following
code ~/.ssh/config
Something like this should popup
Then you're going to add and fill in some syntax
-
Host
will be the shorthand text you type to log into your instance from anywhere in terminal. -
HostName
This you need to get from aws. It's the Public IPv4 address of the instance you want to login to. -
User
This is your instance user. If you created a ubuntu instance keep it as ubuntu. -
IdentityFile
This 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. -
IdentitiesOnly
just 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 ubuntu@00.000.00.000
!
Cautions
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.
Top comments (0)