简体   繁体   English

在 aws ec2 实例上创建用户并添加公钥

[英]Creating a user and adding public key on aws ec2 instance

I've created a user and copied the public key to .ssh/authorized_key for that new user and also I've set the pubkeyauthentication to yes on /etc/ssh/sshd_config after saving the file restarted the sshd service.我已经创建了一个用户并将公钥复制到该新用户的.ssh/authorized_key ,并且在保存文件后重新启动 sshd 服务后,我在/etc/ssh/sshd_config pubkeyauthentication设置为 yes。

When I try to ssh from the new user I am getting error:当我尝试从新用户拨打 ssh 时出现错误:

Permission denied (publickey,gssapi-keyex,gssapi-with-mic)

Am I missing any step here to ssh from the new user account?我是否遗漏了从新用户帐户到 ssh 的任何步骤?

When I check the status for sshd.servive I see error:当我检查 sshd.servive 的状态时,我看到错误:

AuthorizedKeysCommand /opt/aws/bin/eic_run_authorized_keys xxxx SHA256:84NyibLXFppE4BGIM+1e5iO...status 22

Had the same issue error: AuthorizedKeysCommand /opt/aws/bin/eic_run_authorized_keys ec2-user .有同样的问题error: AuthorizedKeysCommand /opt/aws/bin/eic_run_authorized_keys ec2-user

Make sure the file permission is user only (600) in the $HOME/.ssh directory on the SSH client side host.确保在 SSH 客户端主机上的 $HOME/.ssh 目录中的文件权限是仅用户 (600)。

FYI供参考

To debug:调试:

sudo tail -f /var/log/secure to monitor the reason why SSH refuses the connection. sudo tail -f /var/log/secure监控SSH拒绝连接的原因。

Make sure $HOME/.ssh/authorized_key content on EC2 instance is correctly match with your ssh private key in the SSH client host.确保 EC2 实例上的 $HOME/.ssh/authorized_key 内容与 SSH 客户端主机中的 ssh 私钥正确匹配。

Make sure correct private key is being used, use -i option to explicitly specify which key you use.确保使用正确的私钥,使用-i选项明确指定您使用的密钥。

You might want to check the algorithm you are using to generate the key.您可能需要检查用于生成密钥的算法。

I saw exactly the same error message when using the ECDSA algorithm but fixed the problem by using RSA instead (ssh-keygen -t rsa).我在使用 ECDSA 算法时看到了完全相同的错误消息,但改用 RSA (ssh-keygen -t rsa) 解决了这个问题。

If you want to dig deeper you can try如果你想深入挖掘,你可以试试

ssh -Q key 

to get a list of supported key types.获取支持的密钥类型列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM