Azure Cloud Shell에서 파일 유지

Cloud Shell을 처음 시작하면 스토리지 옵션을 선택하라는 메시지가 표시됩니다. Cloud Shell을 사용할 때마다 사용할 수 있는 저장 파일을 원하는 경우 새 스토리지 리소스를 만들거나 기존 스토리지 리소스를 선택해야 합니다. Cloud Shell은 Microsoft Azure Files 공유를 사용하여 세션 전반에 걸쳐 파일을 유지합니다.

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에 매핑됩니다.

참고 항목

SSH 키와 같이 $HOME 디렉터리의 모든 파일은 마운트된 파일 공유에 저장된 사용자 디스크 이미지에서 유지됩니다. 모범 사례를 사용하여 $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에 있는 Azure Files 공유를 변경할 수 있습니다. 사용 가능한 명령을 보려면 clouddrive를 실행합니다.

Group
  clouddrive                  :Manage storage settings for Azure Cloud Shell.

Commands
  mount                       :Mount a file share to Cloud Shell.
  unmount                     :Unmount a file share from Cloud Shell.

새 clouddrive 탑재

Cloud Shell에서 사용하는 공유를 변경하려면 clouddrive mount 명령을 사용합니다.

참고 항목

새 공유를 탑재하는 경우 $HOME 디렉터리에 대한 새 사용자 이미지가 만들어집니다. 이전 $HOME 이미지는 이전 파일 공유에 보관됩니다.

다음 매개 변수를 사용하여 clouddrive mount 명령을 실행합니다.

clouddrive mount -s mySubscription -g myRG -n storageAccountName -f fileShareName

자세한 내용은 clouddrive mount -h를 실행하십시오.

Command
  clouddrive mount            :Mount an Azure file share to Cloud Shell.

    Mount enables mounting and associating an Azure file share to Cloud Shell.
    Cloud Shell will automatically attach this file share on each session start-up.

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

    Cloud Shell persists files with both methods below:
    1. Create a disk image of your $HOME directory to persist files within $HOME.
    This disk image is saved in your specified file share as 'acc_sean.img'' at
    '//<storageaccount>.file.storage.windows.net/<fileshare>/.cloudconsole/acc_sean.img'
    2. Mount specified file share as 'clouddrive' in $HOME for file sharing.
    '/home/sean/clouddrive' maps to '//<storageaccount>.file.storage.windows.net/<fileshare>'

Arguments
  -s | --subscription id          [Required]:Subscription ID or name.
  -g | --resource-group group     [Required]:Resource group name.
  -n | --storage-account name     [Required]:Storage account name.
  -f | --file-share name          [Required]:File share name.
  -d | --disk-size size                     :Disk size in GB. (default 5)
  -F | --force                              :Skip warning prompts.
  -? | -h | --help                          :Shows this usage text.

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

Warning

이 명령을 실행해도 리소스가 삭제되지 않지만 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"):

다음 단계