共用方式為


在 Azure Cloud Shell 中保存檔案

第一次啟動 Cloud Shell 時,系統會提示您選取儲存體選項。 如果想要儲存每次使用 Cloud Shell 時可以使用的檔案,您必須建立新的儲存體資源或選擇現有的儲存體資源。 Cloud Shell 會使用 Microsoft Azure 檔案儲存體共用,以跨工作階段保存檔案。

Cloud Shell 儲存體的運作方式

Cloud Shell 透過下列兩種方法來保存檔案:

  • 建立磁碟映像以包含 $HOME 目錄的內容。 此磁碟映像會儲存至 https://storageaccountname.file.core.windows.net/filesharename/.cloudconsole/acc_user.img。 Cloud Shell 會自動同步處理對此磁碟映像所做的變更。
  • 會在 $HOME 目錄中將檔案共用掛接為 clouddrive/home/<User>/clouddrive 路徑會對應至 storageaccountname.file.core.windows.net/filesharename

注意

$HOME 目錄中的所有檔案 (例如 SSH 金鑰) 都會保存於已掛接檔案共用中儲存的使用者磁碟映像中。 使用最佳做法來保護 $HOME 目錄和掛接檔案共用中的資訊。

保護儲存體存取

為了安全起見,每位使用者都應該建立自己的儲存體帳戶。 若要進行 Azure 角色型存取控制 (RBAC),使用者在儲存體帳戶層級必須具備參與者或更高的存取權。

在指定訂用帳戶內,Cloud Shell 會使用儲存體帳戶中的 Azure 檔案共用。 由於繼承的權限,若使用者具備對訂用帳戶的足夠存取權,便可存取訂用帳戶中包含的儲存體帳戶和檔案共用。

使用者應在儲存體帳戶或訂用帳戶層級設定權限,以鎖定檔案存取權。

Cloud Shell 儲存體帳戶會包含 Cloud Shell 使用者在其主目錄中建立的檔案,其中可能包含存取權杖或認證等敏感性資訊。

使用 Azure 資源原則限制資源建立

在 Cloud Shell 中建立的儲存體帳戶會標記 ms-resource-usage:azure-cloud-shell。 如果您想要禁止使用者在 Cloud Shell 中建立儲存體帳戶,請建立此特定標籤所觸發的 Azure 資源原則

管理 Cloud Shell 儲存體

掛接新的 clouddrive

如果您先前已選取使用 Cloud Shell 的暫時性工作階段,則必須選取在 Cloud Shell 中 [設定] > [重設使用者設定] 來重設喜好設定。 請遵循這些步驟來掛接現有的儲存體帳戶新的儲存體帳戶

注意

如果您要掛接新的共用,則系統會建立 $HOME 目錄的新使用者映像。 先前的 $HOME 映像會保留在先前的檔案共用中。

卸載 clouddrive

您可以隨時卸載 Cloud Shell 檔案共用。 因為 Cloud Shell 需要使用掛接的檔案共用,所以 Cloud Shell 會提示您在下一個工作階段建立並掛接另一個檔案共用。

  1. 執行 clouddrive unmount
  2. 了解並確認提示。

卸載的檔案共用會繼續存在,直到您手動將其刪除為止。 卸載之後,Cloud Shell 就不會在後續工作階段中搜尋此檔案共用。 如需詳細資訊,請執行 clouddrive unmount -h

Command
  clouddrive unmount: Unmount an Azure file share from Cloud Shell.

    Unmount enables unmounting and disassociating a file share from Cloud Shell.
    All current sessions will be terminated. Machine state and non-persisted files will be lost.
    You will be prompted to create and mount a new file share on your next session.
    Your previously mounted file share will continue to exist.

    Note: This command does not unmount storage if the session is Ephemeral.

Arguments
  None

警告

雖然執行此命令不會刪除任何資源,但手動刪除對應至 Cloud Shell 的資源群組、儲存體帳戶或檔案共用,將會清除您的 $HOME 目錄磁碟映像及檔案共用中的任何檔案。 此動作無法復原。

使用 PowerShell 命令

取得目前檔案共用的相關資訊

使用 PowerShell 中的 Get-CloudDrive 命令,來取得有關支援檔案共用之資源的資訊。

PS /home/user> Get-CloudDrive

FileShareName      : cs-user-microsoft-com-xxxxxxxxxxxxxxx
FileSharePath      : //cs7xxxxxxxxxxxxxxx.file.core.windows.net/cs-user-microsoft-com-xxxxxxxxxxxxxxx
MountPoint         : /home/user/clouddrive
Name               : cs7xxxxxxxxxxxxxxx
ResourceGroupName  : cloud-shell-storage-southcentralus
StorageAccountName : cs7xxxxxxxxxxxxxxx
SubscriptionId     : 78a66d97-7204-4a0d-903f-43d3d4170e5b

取消掛接檔案共用

您可以隨時使用 Dismount-CloudDrive Cmdlet,來卸載 Cloud Shell 檔案共用。 卸載 clouddrive 會終止目前工作階段。

Dismount-CloudDrive
Do you want to continue
Dismounting clouddrive will terminate your current session. You will be prompted to create and
mount a new file share on your next session
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"):

下一步