law*_*zlo 14 linux ssh amazon-ec2 permission-denied
当我想要ssh
我的ec2
主人时,我得到了这个权限被拒绝的问题.我试过现有的解决方案,chmod 600 "My.pem"
但仍然没有用.这是我的调试信息:
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: Connecting to 54.223.47.74 [54.223.47.74] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file My.pem type -1
debug1: key_load_public: No such file or directory
debug1: identity file My.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.9
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1
debug1: match: OpenSSH_6.6.1 pat OpenSSH_6.6.1* compat 0x04000000
debug1: Authenticating to 54.223.47.74:22 as 'root'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client chacha20-poly1305@openssh.com <implicit> none
debug1: kex: client->server chacha20-poly1305@openssh.com <implicit> none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:tfjxcE5kePSv1cJK7SWBp/56kgm2DQkyPLSLZ4d73Io
debug1: Host '54.223.47.74' is known and matches the ECDSA host key.
debug1: Found key in /Users/tan/.ssh/known_hosts:24
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic
debug1: Next authentication method: publickey
debug1: Trying private key: My.pem
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic
debug1: No more authentication methods to try.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
Run Code Online (Sandbox Code Playgroud)
小智 28
我使用命令在我的centos机器中解决了这个问题:
ssh -i <Your.pem> ec2-user@<YourServerIP>
Run Code Online (Sandbox Code Playgroud)
这是关于userName,ec2-user
在我的情况下.
lio*_*rko 11
通过与用户连接centos
而不是解决ec2-user
.
除了这里提到的用户名问题之外,它很可能是一个问题。
对我来说,这是公钥不匹配。这就是我解决它的方法。我使用的是带有 ssh 客户端的 Mac。
您可以通过运行以下命令从 .pem 文件获取本地公钥:
ssh-keygen -y -f /path_to_key_pair/my-key-pair.pem
Run Code Online (Sandbox Code Playgroud)
在您的实例上导航到您的authorized_keys 文件,通常可以在此处找到该文件:
/home/username/.ssh/authorized_keys
Run Code Online (Sandbox Code Playgroud)
将您的公钥添加到此文件中。保存并完成。应该可以做到这一点。
只是一些关于我为什么遇到这个问题的背景。我必须创建一个新的 .pem 文件,因为我在启动实例时丢失了下载的文件。出于安全原因,无法再次下载该文件。当我创建一个新的 .pem 文件时,这会用它创建一个新的公钥。由于authorized_keys 文件仍然指向旧的公钥,因此需要在实例上手动更新此公钥。
还有更正式的 9 个步骤流程可以对此进行排序。看这里。
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/replacing-lost-key-pair.html
我注意到每个 Linux 实例都使用默认的 Linux 系统用户帐户启动。这可能与 不同ec2-user
,具体取决于您的实例。您使用以下命令登录,其中DefaultUserName
代表下面引用的用户名。
ssh -i <Your.pem> <DefaultUserName>@<YourPublicServerIP>
Run Code Online (Sandbox Code Playgroud)
每个 Linux 实例都使用默认的 Linux 系统用户帐户启动。默认用户名由启动实例时指定的 AMI 确定。
- 对于Amazon Linux 2或 Amazon Linux AMI,用户名为ec2-user。
- 对于CentOS AMI,用户名为centos。
- 对于Debian AMI,用户名为admin。
- 对于Fedora AMI,用户名为ec2-user或fedora。
- 对于RHEL AMI,用户名为ec2-user或root。
- 对于SUSE AMI,用户名为ec2-user或root。
- 对于Ubuntu AMI,用户名为ubuntu。
- 否则,如果 ec2-user 和 root 不起作用,请与 AMI 提供商联系。
小智 7
您可以在此处找到 ec2 实例的默认用户名:https : //alestic.com/2014/01/ec2-ssh-username/
但如果您想查找实例的用户名:单击“连接”按钮以查看默认用户名。
找到用户名后,运行此命令,以确保您的密钥不可公开查看。
chmod 400 <private-key-file.pem>
Run Code Online (Sandbox Code Playgroud)
然后使用其公共 DNS 或 IP 连接到您的实例:
ssh -i <private-key-file.pem> ec2-user@<public ip>
Run Code Online (Sandbox Code Playgroud)
gil*_*web -3
终端报错的解决方法
权限被拒绝(publickey、gssapi-keyex、gssapi-with-mic、密码)。
ssh-keygen -f " ~/.ssh/known_hosts" -R xx.xx.xxx.xxx
Run Code Online (Sandbox Code Playgroud)
xx - IP 主机
归档时间: |
|
查看次数: |
32624 次 |
最近记录: |