![AWS:难以更改服务器密钥-权限被拒绝(公钥)](https://linux22.com/image/630001/AWS%EF%BC%9A%E9%9A%BE%E4%BB%A5%E6%9B%B4%E6%94%B9%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%AF%86%E9%92%A5-%E6%9D%83%E9%99%90%E8%A2%AB%E6%8B%92%E7%BB%9D%EF%BC%88%E5%85%AC%E9%92%A5%EF%BC%89.png)
正在努力解决一个常见问题。尴尬的是,我之前已经按照下面链接的指南成功了,并且已经完全建立了一个运行 Ubuntu 并引用 RDS 数据库实例的 Amazon Web Services LAMP 堆栈。
这是我在这个特定场景中遇到的问题,参考本指南:
http://jeffreifman.com/detailed-wordpress-guide-for-aws/secure-your-instance/
- 启动了 m1。运行 Ubuntu 12.04 LTS 64 位的微实例。
- 创建 AWS 安全密钥,将私钥下载到 ~/.ssh 文件夹
- SSH 使用私钥和 root 登录
- 创建新的管理员用户
- 将管理员用户添加到管理员组
- 将用户添加到 sudoers 列表
- 将用户更改为新用户
- 生成新的安全密钥对
- 在 authorized_keys 列表中添加了新的安全密钥对
- 将.ssh文件夹的权限设置为600
- 编辑 sshd_config 以允许来自 ubuntu 的用户和新用户
- 重新启动 SSH 服务
- SFTP 从服务器上的 tmp 文件夹下载私钥
- .ssh 远程文件夹权限当前设置为 700。私钥设置为 400,公钥设置为 600。
- 本地 ~/.ssh/ 私钥权限设置为 600。
此时,我已尝试通过 SSH 重新进入服务器[电子邮件保护]引用新的私钥,我收到“权限被拒绝(公钥)”警告。
如能得到任何帮助解决此问题,我们将不胜感激。
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 my.ip.address [my.ip.address] port 22.
debug1: Connection established.
debug1: identity file /Users/myfiles/.ssh/my_key type -1
debug1: identity file /Users/myfiles/.ssh/my_key-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_5.9p1 Debian- 5ubuntu1.1
debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1.1 pat OpenSSH_5*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 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 my.pub.key
debug1: Host '54.72.105.9' is known and matches the RSA host key.
debug1: Found key in /Users/lloyd/.ssh/known_hosts:6
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 DSA public key: /Users/lloyd/.ssh/id_fkadmin
debug1: Authentications that can continue: publickey
debug1: Offering DSA public key: /Users/lloyd/.ssh/id_nutriciaadmin
debug1: Authentications that can continue: publickey
debug1: Trying private key: /Users/lloyd/.ssh/id_nutriciaadmin
debug1: key_parse_private_pem: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
答案1
您需要告诉本地计算机现在要使用哪个密钥。您可以在根级别添加它,但如果您添加了两个密钥,它将简单地尝试它们。首选方法是为 ssh 创建一个 conf 文件
touch ~/.ssh/config 然后添加
Host [remote-ip-address] IdentityFile [path to pem file (must be chmod 600)] User [login user]
如果仍然失败,请尝试调试实际的 ssh 连接以查看它尝试使用什么。
ssh -v [用户@主机]