如何使用非 ec2 用户登录 EC2 实例?

如何使用非 ec2 用户登录 EC2 实例?

如何在 amazon linux ami 中使用非 ec2 用户帐户登录?

#useradd -m sample
#passwd sample
set password

#cat /etc/passwd
sample:x:508:1002::/home/monitor/sample:/bin/bash

# cat /home/monitor/sample/.ssh/authorized_keys
command="echo 'Please login as the ec2-user user rather than root
user.';echo;sleep10"    ssh-rsa xxxxxxxxx

# chown -R sample /home/monitor/sample/.ssh

我还将 /root/.ssh/authorized_keys 复制到新用户的 .ssh 目录中

登录时服务器显示“服务器拒绝我们的密钥”并且没有弹出可用的支持的身份验证方法。

如何将样本与我现有的密钥对关联?

答案1

您不应该复制 /root/.ssh/authorized_keys,而应该将 /home/ec2-user/.ssh/authorized_keys 复制到新用户的 authorized_keys 文件中。您还需要确保权限设置正确。

例如:

rsync -a /home/ec2-user/.ssh /home/monitor/sample/
chown -R sample:sample /home/monitor/.ssh

相关内容