파일 시스템에만 액세스할 수 있는 AWS 호스팅 Ubuntu 서버 사용자 계정 잠금 해제

파일 시스템에만 액세스할 수 있는 AWS 호스팅 Ubuntu 서버 사용자 계정 잠금 해제

Ubuntu Server AMI 중 하나를 사용하여 AWS 인스턴스를 시작하고 기본 사용자(ubuntu) 및 키 파일로 성공적으로 로그온하고 일부 항목을 설치하고 일부 사용자를 추가한 후 연결을 끊고 몇 주 동안 잊어버렸습니다.

오늘 나는 처음에 괜찮았던 것과 동일한 자격 증명을 사용하여 더 이상 SSH로 연결할 수 없다는 것을 발견했습니다.

$ ssh -i ~/path/key.pem [email protected]
Connection closed by 1.2.3.4 port 22

$ ssh -v -i ~/path/key.pem [email protected]
OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n  7 Dec 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 1.2.3.4 [1.2.3.4] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /path/key.pem type -1
debug1: key_load_public: No such file or directory
debug1: identity file /path/key.pem-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.3
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.6p1 Ubuntu-4ubuntu0.3
debug1: match: OpenSSH_7.6p1 Ubuntu-4ubuntu0.3 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 1.2.3.4:22 as 'ubuntu'
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:a/4u6R0qGP4SviSke0OWOOIaSjqymNvexBZDJ+yoOXc
debug1: Host '1.2.3.4' is known and matches the ECDSA host key.
debug1: Found key in /home/user/.ssh/known_hosts:45
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=<ssh-ed25519,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: RSA SHA256:nd8gr8BrgC88h1hobmvdNMHOWNmWukYc4L0SJswVolk user@host
debug1: Authentications that can continue: publickey
debug1: Trying private key: /path/key.pem
Connection closed by 1.2.3.4 port 22

그래서 인스턴스를 중지하고 볼륨을 분리한 다음 로그온할 수 있는 인스턴스에 볼륨을 연결했습니다. 이를 통해 볼륨을 마운트하고, 파일에 액세스하고, SSH 구성 및 로그를 연구할 수 있습니다.

다음은 사용자 계정이 어떤 이유로 잠겨 있음을 발견한 방법입니다.

$ cd /path/to/mounted/volume
$ tail var/log/auth.log
Mar 15 13:10:24 sshd[1145]: Server listening on 0.0.0.0 port 22.
Mar 15 13:10:24 sshd[1145]: Server listening on :: port 22.
Mar 15 13:14:09 sshd[1430]: User ubuntu not allowed because account is locked
Mar 15 13:17:01 CRON[1440]: pam_unix(cron:session): session opened for user root by (uid=0)
Mar 15 13:17:01 CRON[1440]: pam_unix(cron:session): session closed for user root
Mar 15 13:26:07 sshd[1473]: User another_user not allowed because account is locked
Mar 15 13:26:07 sshd[1473]: Connection closed by invalid user another_user 212.93.116.117 port 36868 [preauth]
Mar 15 13:27:42 sshd[1475]: Bad protocol version identification '\377\364\377\375\006\033\033' from 212.93.116.117 port 36872
Mar 15 13:28:05 sshd[1476]: User ubuntu not allowed because account is locked
Mar 15 13:36:37 sshd[1145]: Received signal 15; terminating.

another_user를 생성하고 키 인증을 설정하고 SSH 비밀번호 로그인을 비활성화할 때 비어 있지 않은 비밀번호를 지정하는 것을 잊어버렸습니다. 따라서 해당 사용자가 잠긴 이유일 수 있습니다. 어쨌든, 나는 이제 SSH 액세스 문제가 해결되는지 확인하기 위해 적어도 일시적으로 사용자 우분투를 잠금 해제하는 방법을 찾고 있습니다. 하지만 보시다시피 시스템 명령을 사용할 수 없으며 시스템 파일을 직접 편집하여 사용할 수 있어야 합니다.

답변1

사용자 로그인을 다시 활성화하려면 한 파일에서 한 문자를 변경하는 것으로 충분했습니다 ubuntu.

$ cd /path/to/mounted/volume
$ sudo nano etc/shadow

# Searh for the row that starts with "ubuntu:!"
# Change the "!" to "*", save, exit

손상된 인스턴스에 볼륨을 다시 연결하고 부팅한 후 이제 ubuntu 사용자로 정상적으로 로그인이 가능해졌습니다. 이 사용자가 왜 자동으로 잠겼는지 아직도 모르겠습니다. 생성된 다른 사용자에 대해서는 비밀번호가 비어 있어서 잠긴 것으로 추정되는데, 이를 증명할 수 있는 참고자료가 없습니다.

관련 정보