我已经阅读了很多关于这个主题的帖子,但没有人帮助我解决我的问题。
我有一台机器亚马逊ec2,我用这个SSH命令连接:
ssh -i /Library/AWS/glrpopulis.pem ec2-user@54.225.154.23
到目前为止,我从未遇到过这个命令的问题。它刚停止工作,显示以下消息:权限被拒绝(公钥)。无处不在!
我真的无法理解为什么我几乎每天都使用相同的命令而无法正常工作。可能我已经改变了一些我不应该做的事情,但是我很难搞清楚什么。
我是第一次发生网络应用程序(atlassian bamboo)时创建的服务,但我不确定这是否与错误有关。
我已经重启机器几次并一遍又一遍地尝试,但没有成功。
使用-v选项的完整输出显示如下:
mac-pipo:~ felipereis$ ssh -v -i /Library/AWS/glrpopulis.pem ec2-user@54.225.154.23
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to 54.225.154.23 [54.225.154.23] port 22.
debug1: Connection established.
debug1: identity file /Users/felipereis/.ssh/id_rsa type 1
debug1: identity file /Users/felipereis/.ssh/id_rsa-cert type -1
debug1: identity file /Users/felipereis/.ssh/id_dsa type -1
debug1: identity file /Users/felipereis/.ssh/id_dsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.2
debug1: match: OpenSSH_6.2 pat OpenSSH*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5-etm@openssh.com none
debug1: kex: client->server aes128-ctr hmac-md5-etm@openssh.com none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA 19:ef:f1:2b:56:dd:86:ec:42:65:ff:1d:6b:64:0f:f3
debug1: Host '54.225.154.23' is known and matches the RSA host key.
debug1: Found key in /Users/felipereis/.ssh/known_hosts:12
debug1: ssh_rsa_verify: signature correct
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
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/felipereis/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Offering RSA public key: /Library/AWS/glrpopulis.pem
debug1: Authentications that can continue: publickey
debug1: Trying private key: /Users/felipereis/.ssh/id_dsa
debug1: No more authentication methods to try.
Permission denied (publickey).
更新: *我刚刚测试过,我可以使用相同的密钥(glrpopulis.pem)连接到不同的ec2实例,所以可能会在第一台机器上运行
答案 0 :(得分:0)
听起来像〜/ .ssh / authorized_keys下的键搞砸了或者文件被删除了。
尝试以下方法:
Volume A
Volume A
作为/dev/sdf
mkdir -p /mnt/xvdf
mount /dev/xvdf /mnt/xvdf
cp ~/.ssh to /mnt/xvdf/home/ec2-user/.
chmod 700 /mnt/xvdf/home/ec2-user
chmod 600 /mnt/xvdf/home/ec2-user/authorized_keys
Volume A
Volume A
。您现在应该可以登录了。
答案 1 :(得分:0)
根据您的AMI,公钥可能会被添加到ec2-user的其他用户的authorized_keys文件中。
要找到答案,您可以在EC2控制台中查看实例的启动日志,并且应该输出cloud-init用作“默认用户”的用户名。我有这样一条线:
ci-info: +++++++++++++++++++++Authorized keys from /home/ec2-user/.ssh/authorized_keys for user ec2-user++++++++++++++++++++++
您也可以尝试以root用户身份登录,因为有时会出现“请以用户身份登录”ec2-user“而不是用户”root“这样的错误。”
这件事发生在我身上,因为我更新了我的cloud-init版本,这就是将公钥添加到authorized_keys的原因。替换了默认配置文件(/etc/cloud/cloud.cfg
),导致默认用户从“ec2-user”更改为“cloud-user”。
我修改了此问题,方法是将新/etc/cloud/cloud.cfg
的system_info部分更改为:
...
system_info:
...
default_user:
name: ec2-user
sudo: ALL=(ALL) NOPASSWD:ALL
...
然后,您可以从该实例创建一个新的AMI,它应该再次正确设置ec2-user。