Skip to content
Advertisement

Login to Amazon EC2 via ssh

I have a question and am stuck at something. I recently created AWS EC2 Ubuntu instance with default settings. I have an Ubuntu machine locally as well and so far I managed to connect successfully to the Ubuntu instace with this command

ssh -i /var/www/my-key-pair.pem ec2-user@ec2-198-51-100-1.compute-1.amazonaws.com

However I want to know if there is a simpler way to login to ssh without passing the private key everytime I login and add its ip to my ~/.ssh/config so that I could login as easily as ssh ubuntu@some.ip.number. By the way I am using AWS free tier package.

Advertisement

Answer

Create ~/.ssh/config with:

Host myhost
  IdentityFile /var/www/my-key-pair.pem
  Use ec2-user
  Hostname ec2-198-51-100-1.compute-1.amazonaws.com

And the you can login using ssh myhost.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement