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 [email protected]
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 [email protected]. By the way I am using AWS free tier package.
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.
ssh-add -K /var/www/my-key-pair.pem will permanently add your private key as identity file in ~/.ssh/config.
Thus, ssh username@ip_address_of_ec2_instance works.
To avoid typing username and IP address every time, add to .ssh/config:
Host my-instance
HostName some.ip.address.here
User username
With this config, you can simply do ssh my-instance to remote login.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With