Google-Cloud-Platform

GCE 刪除的使用者文件夾在重啟後重新出現

  • February 27, 2019

在新創建的 gce 實例上,我發現一個非常混亂的/home/文件夾,其中包含每個具有足夠權限的 GCP 使用者的主目錄(到目前為止還不算太瘋狂),但也適用於任何通過 gcloud 成功通過 ssh 登錄到任何相同 gce 的使用者項目(即使那個使用者實際上從未嘗試過 ssh-ing 到那個 gce 實例)

gcloud compute ssh username@gce-instance --project project-name

最後這件事對我來說似乎莫名其妙,但無論如何我決定在新創建的 Ubuntu 18.04 gce 上刪除所有這些 linux 使用者,deluser --remove-all-files命令如下所示:

CURRENT_USER=username
for USER in `ls /home`
 do
   if [ $CURRENT_USER -neq $USER ]
     then 
       deluser --remove-all-files $USER
     fi
 done

因此,除目前使用者之外的所有使用者都將被刪除,並且他們的主文件夾不會出現在 中ls /home/,但這只是暫時的,因為它們會在下次重新啟動 gce 後重新出現,所有這些使用者。

我看了看journalctl,並註意到這是由於google-accounts守護程序,它在啟動時創建了所有這些使用者。我發現了執行此操作的程式碼/usr/lib/python3/dist-packages/google_compute_engine/accounts/accounts_daemon.py,我什至嘗試google_compute_engine.accounts.accounts_daemon.AccountsDaemon()從 python CLI 實例化一個並執行它的HandleAccounts(res)方法,journalctl看起來非常有前途:

Feb 27 15:32:57 gce-name google-accounts[1922]: WARNING Exception locking /var/lock/google_accounts.lock. File already locked.
Feb 27 15:33:18 gce-name google-accounts[1935]: WARNING Exception locking /var/lock/google_accounts.lock. File already locked.
Feb 27 15:33:35 gce-name google-accounts[1935]: WARNING Instance attributes were not found.
Feb 27 15:33:35 gce-name google-accounts[1935]: WARNING Project attributes were not found.
Feb 27 15:33:35 gce-name google-accounts[1935]: WARNING Instance attributes were not found.
Feb 27 15:33:35 gce-name google-accounts[1935]: WARNING Project attributes were not found.
Feb 27 15:33:36 gce-name google-accounts[1935]: INFO Removing user username_1.
Feb 27 15:33:36 gce-name google-accounts[1935]: INFO Removing user username_2.
### etc ###
Feb 27 15:33:36 gce-name google-accounts[1935]: INFO Removing user username_last.

不幸的是,在最後一次非常自信之後sudo reboot now,我驚恐地發現每個文件夾都又回到了裡面/home/

我的想法用完了,有人可以幫助我嗎?

轉到 GCP 的控制台,然後在 Compute Engine 中,轉到元數據。您會發現所有已添加為項目槓桿的 SSH-KEY。每次創建新 VM 時,所有使用 SSH 密鑰作為項目級別的使用者都將有權訪問該 VM。

有關更多資訊,請參閱此連結: https ://cloud.google.com/compute/docs/storing-retrieving-metadata

引用自:https://serverfault.com/questions/955995