从用户 ssh 目录中删除了 authorized_keys

从用户 ssh 目录中删除了 authorized_keys

用户从 ec2-user ssh 目录中删除了 authorized_keys,现在无法通过 putty 使用 ppk 文件登录。

我仍然可以以其他用户身份访问服务器,但是该用户没有 sudo 访问权限。

唯一具有 sudo 访问权限的用户是 ec2-user。

我尝试从 ppk 文件上传公钥和私钥并使用

ssh -v -i ec2-userprivate [email protected]

我还可以尝试其他什么吗?

[oracle@ip-172-31-62-50 ~]$ ssh -v -i ec2-userprivate [email protected]
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 58: Applying options for *
debug1: Connecting to 127.0.0.1 [127.0.0.1] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file ec2-userprivate type -1
debug1: key_load_public: No such file or directory
debug1: identity file ec2-userprivate-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: match: OpenSSH_7.4 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 127.0.0.1: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: kex: curve25519-sha256 need=64 dh_need=64
debug1: kex: curve25519-sha256 need=64 dh_need=64
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:truUDHodSW7Zjq/jaruRD7MlYmN0l2vDmxhspUDfwdE
debug1: Host '127.0.0.1' is known and matches the ECDSA host key.
debug1: Found key in /home/oracle/.ssh/known_hosts:10
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,gssapi-keyex,gssapi-with-mic
debug1: Next authentication method: gssapi-keyex
debug1: No valid Key exchange context
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure.  Minor code may provide more information
No Kerberos credentials available (default cache: KEYRING:persistent:1001)

debug1: Unspecified GSS failure.  Minor code may provide more information
No Kerberos credentials available (default cache: KEYRING:persistent:1001)

debug1: Next authentication method: publickey
debug1: Trying private key: ec2-userprivate
Enter passphrase for key 'ec2-userprivate':
debug1: No more authentication methods to try.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

答案1

解决此问题的唯一方法是卸载 EBS 块并将其附加到另一个正在运行的 EC2 实例并添加 authorized_keys 文件。

  1. 关闭您需要修复的实例。
  2. 从您的实例中分离 EBS 块。
  3. 使用默认设置创建一个新实例。类型无关紧要。如果您真的愿意,甚至可以使用 t3.nano 现货实例来执行此操作。
  4. 将 EBS 块附加到新的 EC2 实例
  5. 登录新的 EC2 实例,使用 sudo 挂载新的 EBS 块。
  6. cd 到挂载上的用户目录并使用必要的公钥创建 authorized_users 文件。
  7. 关闭实例,分离 EBS 块,然后将其重新安装到另一个实例。

相关内容