如何重新创建ec2-user主目录

时间:2016-05-13 15:05:54

标签: amazon-web-services ssh amazon-ec2 rhel

我在亚马逊ec2上的rhel实例上永久删除了我的ec2-user主目录

谢天谢地,我仍然登录了我的服务器

我没有目录或快照的任何备份副本

我知道我可以从私钥重新创建公钥,并且还将我的公钥复制到/home/ec2-user/.ssh/authorized_keys 这就是我重新创建公钥的方式

ssh-keygen -y -f test.pem > test.pub

由于某种原因,这些步骤还不够,我仍然无法进入我的服务器

我错过了任何步骤吗?有人可以指导我吗?

这是我尝试登录时遇到的错误

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
xx.
Please contact your system administrator.
Add correct host key in /Users/xx/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/xx/.ssh/known_hosts:5
ECDSA host key for ec2-xx-xx-xx-xx.compute-1.amazonaws.com has changed and you have requested strict checking.
Host key verification failed.

1 个答案:

答案 0 :(得分:1)

将您的公钥复制到/home/ec2-user/.ssh/authorized_keys 创建.ssh目录和authorized_keys文件(如果它们不存在)

以root身份执行这些命令

chown -R ec2-user /home/ec2-user 
chmod 700 /home/ec2-user/.ssh
chmod 600 /home/ec2-user/.ssh/authorized_keys

然后尝试登录。认为这可能足以使其工作