Amazon EC2 登录

Amazon EC2 登录

当我在 /etc/passwd 文件中将 Amazon EC2 实例的主目录从 /home/ubuntu 更改为 /home/ubuntu/folder 时,我无法再使用现有密钥对访问该实例。一旦我将其切换回原始目录,我就不会遇到任何问题,并且可以正常登录我的实例。我已检查新文件夹的权限,它们是 drwxr-xr-x,与 /home/ubuntu 文件夹相同。我目前有多个实例正在运行,由于这一变化,我无法重新登录它们来纠正这种情况。有人知道发生了什么吗?

答案1

您需要将 .ssh 文件夹复制到新目录(好像您已经这样做了,但还是提醒您一下)。如果您使用的是 StrictMode,您还必须确保 .ssh 文件夹具有正确的权限(见下文)

StrictModes

Specifies whether sshd should check file modes and ownership of the user’s files 
and home directory before accepting login. This is normally desirable because novices 
sometimes accidentally leave their directory or files world-writable. The default is yes.

严格模式所需的权限

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

相关内容