
おい。月曜日だ。
cron がホーム フォルダーに書き込んでいるいくつかのファイルに php がアクセスできるように、次のコマンドを実行しました。
chown ec2-user:apache /home/ec2-user
chmod 2775 /home/ec2-user
# the owner of /home/ec2-user used to be root:root. I intended to change to root:apache, but copy/pasted this line from somewhere and didn't proofread.
接続が切断されるまでは問題なく動作していましたが、今はサーバーにSSH接続できなくなりました。エラーはPermission denied (publickey,gssapi-keyex,gssapi-with-mic)
サーバーへのアクセスを回復するためのアイデアはありますか?
これは AWS 上の Amazon Linux 2 インスタンスです。
答え1
私がこれを解決した方法は次のとおりです (@MisterSmith によるシステム マネージャーのコメントに感謝します)。
「AWS System Manager」にアクセス > 自動化
検索し
AWSSupport-TroubleshootSSH
て選択します。インスタンスを選択します(「管理対象インスタンスを表示」の選択を「すべてのインスタンスを表示」に変更する必要がありました)
アクションを「すべてチェック」に変更し、オフラインを許可するを「True」に設定して実行します。
(インスタンスの停止/開始は実行の一部として実行されました)
結果出力:
----------[Diagnostic Results]----------
module run/openssh [SUCCESS] All configuration checks passed or all detected problems fixed.
-- FIXED Permission mode includes write for groups and/or other users: /home/ec2-user
-- FIXED Missing authorized key directory: /home/ssm-user/.ssh
-- FIXED Missing authorized key file: /home/ssm-user/.ssh/authorized_keys
-- FIXED Permission mode includes permissions for groups and/or other users: /etc/ssh/ssh_host_rsa_key
-- FIXED Permission mode includes permissions for groups and/or other users: /etc/ssh/ssh_host_ecdsa_key
-- FIXED Permission mode includes permissions for groups and/or other users: /etc/ssh/ssh_host_ed25519_key
SSH アクセスをテストしましたが、すべてが以前と同じように動作しています。
興味深いことに、ホームフォルダ所有者変更されていません。上記の出力の別の部分で問題が修正されました。
ls -hal of /home/ec2-user in broken state:
drwxrwsr-x 7 ec2-user apache 4.0K May 18 06:59
ls -hal in repaired state:
drwxr-sr-x 7 ec2-user apache 4.0K May 18 06:59