ファイルシステムにのみアクセスできるように、AWSホスティングUbuntuサーバーユーザーアカウントのロックを解除します。

ファイルシステムにのみアクセスできるように、AWSホスティングUbuntuサーバーユーザーアカウントのロックを解除します。

Ubuntu Server AMI の 1 つを使用して 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アクセスの問題が解決されることを確認するために、少なくとも一時的にユーザーのUbuntuをロック解除する方法を探しています。ただし、ご覧のとおり、システムコマンドは使用できず、システムファイルを直接編集してこれを実行できる必要があります。

ベストアンサー1

ファイル内の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ユーザーを使用して正常にログインできるようになりました。このユーザーがなぜ自動的にロックされたのかはまだわかりません。作成された他のユーザーにはパスワードが空でロックされているようですが、これを証明するための参考資料はありません。

おすすめ記事