[英]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. 我最近使用默认设置创建了AWS EC2 Ubuntu实例。 I have an Ubuntu machine locally as well and so far I managed to connect successfully to the Ubuntu instace with this command 我本地也有一台Ubuntu机器,到目前为止,我设法使用此命令成功连接到Ubuntu实例
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
. 但是我想知道每次登录时是否有更简单的方法登录ssh而不传递私钥,并将其ip添加到我的~/.ssh/config
以便我可以像ssh ubuntu@some.ip.number
一样轻松ssh ubuntu@some.ip.number
。 By the way I am using AWS free tier package. 顺便说一句,我正在使用AWS免费套餐包。
Create ~/.ssh/config
with: 使用以下命令创建~/.ssh/config
:
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 myhost
登录。
ssh-add -K /var/www/my-key-pair.pem
will permanently add your private key as identity file in ~/.ssh/config
. ssh-add -K /var/www/my-key-pair.pem
会将您的私钥永久添加为~/.ssh/config
身份文件。
Thus, ssh username@ip_address_of_ec2_instance
works. 因此, ssh username@ip_address_of_ec2_instance
有效。
To avoid typing username and IP address every time, add to .ssh/config
: 为避免每次都输入用户名和IP地址,请添加到.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. 使用此配置,您只需执行ssh my-instance
即可进行远程登录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.