简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM