
哎喲。是星期一。
我運行了這些命令,以便 php 可以存取 cron 寫入主資料夾的一些檔案:
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 系統管理員”> 自動化
搜尋
AWSSupport-TroubleshootSSH
並選擇它。選擇實例(我必須將“顯示託管實例”選擇更改為“顯示所有實例”)
將操作變更為“檢查全部”並將允許離線變更為“真”,然後執行
(實例的停止/啟動是作為執行的一部分執行的)
結果輸出:
----------[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