正如标题所述。我愚蠢地将权限 home/ec2-user
递归更改为 777,之后我无法登录。然后我分离了卷,然后将其附加到另一个实例,并将该文件夹的权限递归更改为 700。现在,当我尝试使用以下命令连接到它时,我收到错误
ssh -v -i ~/Amazon-fooDev/fooDev.pem [email protected]
OpenSSH_7.8p1, LibreSSL 2.7.3
debug1: Reading configuration data /Users/admin/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug1: Connecting to ec2-34-212-108-144.us-west-2.compute.amazonaws.com port 22.
debug1: Connection established.
debug1: identity file /Users/admin/Amazon-fooDev/fooDev.pem type -1
debug1: identity file /Users/admin/Amazon-fooDev/fooDev.pem-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.8
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: match: OpenSSH_7.4 pat OpenSSH_7.0*,OpenSSH_7.1*,OpenSSH_7.2*,OpenSSH_7.3*,OpenSSH_7.4*,OpenSSH_7.5*,OpenSSH_7.6*,OpenSSH_7.7* compat 0x04000002
debug1: Authenticating to ec2-34-212-108-144.us-west-2.compute.amazonaws.com:22 as 'ec2-user'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:XJWnn7TLa5feJVY7kAOUJQGmWm8J3UNQ/MM+uQZa+Sk
debug1: Host 'ec2-34-212-108-144.us-west-2.compute.amazonaws.com' is known and matches the ECDSA host key.
debug1: Found key in /Users/admin/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /Users/admin/Amazon-fooDev/fooDev.pem
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
[email protected]: Permission denied (publickey).
关于如何解决此问题,您有什么建议吗?我浪费了一整天的时间尝试连接到该实例并恢复到其原始状态。任何建议都将不胜感激。700 权限是否home/ec2-user
正确?或者我应该将其更改为其他权限?您认为我可能找错了方向吗?
以下是一些最新权限的列表
[root@ip-172-31-42-113 vol1]# chmod 600 home/ec2-user/.ssh/authorized_keys
[root@ip-172-31-42-113 vol1]# ls -l
total 120
dr-xr-xr-x 2 root root 4096 Nov 17 09:05 bin
dr-xr-xr-x 4 root root 4096 Nov 17 09:05 boot
drwxr-xr-x 2 root root 4096 Feb 28 2014 cgroup
drwxr-xr-x 2 root root 4096 Aug 11 01:27 dev
drwxr-xr-x 83 root root 4096 Nov 27 01:51 etc
drwx------ 3 root root 4096 Nov 17 05:10 home
dr-xr-xr-x 7 root root 4096 Nov 17 08:48 lib
dr-xr-xr-x 10 root root 12288 Nov 17 09:05 lib64
drwxr-xr-x 2 root root 4096 Aug 11 01:26 local
drwx------ 2 root root 16384 Aug 11 01:26 lost+found
drwxr-xr-x 2 root root 4096 Jan 6 2012 media
drwxr-xr-x 2 root root 4096 Jan 6 2012 mnt
drwxr-xr-x 3 root root 4096 Aug 11 01:26 opt
drwxr-xr-x 2 root root 4096 Aug 11 01:26 proc
dr-xr-x--- 5 root root 4096 Nov 26 12:00 root
drwxr-xr-x 3 root root 4096 Nov 17 05:10 run
dr-xr-xr-x 2 root root 12288 Nov 17 09:05 sbin
drwxr-xr-x 2 root root 4096 Jan 6 2012 selinux
drwxr-xr-x 2 root root 4096 Jan 6 2012 srv
drwxr-xr-x 2 root root 4096 Aug 11 01:26 sys
drwxrwxrwt 3 root root 4096 Nov 27 03:15 tmp
drwxr-xr-x 16 root root 4096 Nov 22 23:12 usr
drwxr-xr-x 20 root root 4096 Nov 17 08:31 var
[root@ip-172-31-42-113 vol1]# cd home/ec2-user/.ssh/
[root@ip-172-31-42-113 .ssh]# ls -l
total 4
-rw------- 1 ec2-user ec2-user 391 Nov 27 01:51 authorized_keys
答案1
SSH 参数-i
期望下一个参数是键名。
在您的情况下-iv
,告诉ssh
从文件中读取密钥v
- 这不是您想要的:)连锁效应是下一个参数(密钥名称)被视为主机名,显然它无法解析。
这将起作用:
ssh -v -i ~/Amazon-Permission/FooDev.pem ec2-user@ec2-...
更新后再更新:)
如果您进行了递归,chmod 700
它也会更改 authorized_keys 模式。将卷重新安装到您的小“助手”实例并执行以下操作:
chmod 600 home/ec2-user/.ssh/authorized_keys
更新 2
您home/
必须是 模式755
而不是700
。否则ssh
无法检查以 方式打开文件ec2-user
。
chmod 755 home
chmod 700 home/ec2-user home/ec2-user/.ssh
chmod 600 home/ec2-user/.ssh/authorized_keys
希望有帮助:)
答案2
首先,修复语法错误。你说你使用了:
ssh -iv ~/Amazon-Permission/FooDev.pem [email protected]
这会尝试加载名为 的 ssh 私钥v
,但这不是您想要的。您需要名为 的 ssh 私钥~/Amazon-Permission/FooDev.pem
。删除v
不知为何进入其中的杂散密钥。