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

P K*_*P K 3 amazon-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
Run Code Online (Sandbox Code Playgroud)

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

在登录时服务器说'服务器拒绝我们的密钥'并且没有支持的认证方法可用弹出窗口.

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

Kev*_*ock 8

您复制了根密钥,而不是ec2-user密钥.您应该复制这些密钥,然后确保您已设置适当的权限.

cp -r~ec2-user/.ssh~sample

chown -R sample:sample~sample/.ssh

chmod 700~sample/.ssh

chmod 600~sample/.ssh/authorized_keys

如果这不能解决问题,请运行详细的ssh连接,并粘贴结果(删除任何相关信息)

ssh -i [keyfile] [user] @ [ip] -v

我会尽力帮助更多.