申请的亚马逊云服务器EC2,实例为ubuntu系统
一、打开终端,定位到放置密钥的文件夹;
二、确保私有秘钥不是公开可见的:
chmod 400 密钥文件名.pem
三、两种方式连接云服务器:(假设实例的对公IP为:11.22.33.44)
ssh -i 密钥文件名.pem ec2-user@11.22.33.44
ssh -i 密钥文件名.pem ec2-user@ec2-11-22-33-44.us-east-2.compute.amazonaws.com
两种方式均报错:
Permission denied (publickey).
四、解决方法:
在亚马逊官方文档中有下面一段:
Get the default user name for the AMI that you used to launch your instance
-
For an Amazon Linux AMI, the user name is
ec2-user
. -
For a Centos AMI, the user name is
centos
. -
For a Debian AMI, the user name is
admin
orroot
. -
For a Fedora AMI, the user name is
ec2-user
orfedora
. -
For a RHEL AMI, the user name is
ec2-user
orroot
. -
For a SUSE AMI, the user name is
ec2-user
orroot
. -
For an Ubuntu AMI, the user name is
ubuntu
orroot
. -
Otherwise, if
ec2-user
androot
don't work, check with the AMI provider.
最后一条说明存在使用ec2-user和root不能连接的情况,所以需要多尝试一下,由于我装的是ubuntu系统,直接将连接命令中的ec2-user换成ubuntu,完美连接。