azure - 重新启动后网络驱动器请求登录时映射到 Win10 的 Azure 文件存储
问题描述
我正在使用 Azure 文件存储,并且一直将存储映射为我的物理 Windows 10 PC 上的网络驱动器 U。我使用 PowerShell 安装它:
net use U: \\exampleaccount.file.core.windows.net\filesharename /u:AZURE\exampleaccount AzureAccessKey /persistent:Yes
但是,每次我重新启动 PC 时,网络驱动器都会要求我输入与存储帐户关联的凭据。
1) Windows 不存储最初用于映射驱动器的 AzureAccessKey 密钥吗?
2)每次重新启动系统时自动修复此问题的最简单方法是什么?
解决方案
请参阅此处的文档以在 Windows 中保留 Azure 文件共享凭据:
cmdkey实用程序允许您将存储帐户凭据存储在 Windows 中。这意味着当您尝试通过其 UNC 路径访问 Azure 文件共享或装载 Azure 文件共享时,您无需指定凭据。若要保存存储帐户的凭据,请运行以下 PowerShell 命令,
<your-storage-account-name>
并<your-resource-group-name>
在适当的地方进行替换。
$resourceGroupName = "<your-resource-group-name>"
$storageAccountName = "<your-storage-account-name>"
# These commands require you to be logged into your Azure account, run Login-AzAccount if you haven't
# already logged in.
$storageAccount = Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName
$storageAccountKeys = Get-AzStorageAccountKey -ResourceGroupName $resourceGroupName -Name $storageAccountName
# The cmdkey utility is a command-line (rather than PowerShell) tool. We use Invoke-Expression to allow us to
# consume the appropriate values from the storage account variables. The value given to the add parameter of the
# cmdkey utility is the host address for the storage account, <storage-account>.file.core.windows.net for Azure
# Public Regions. $storageAccount.Context.FileEndpoint is used because non-Public Azure regions, such as sovereign
# clouds or Azure Stack deployments, will have different hosts for Azure file shares (and other storage resources).
Invoke-Expression -Command ("cmdkey /add:$([System.Uri]::new($storageAccount.Context.FileEndPoint).Host) " + `
"/user:AZURE\$($storageAccount.StorageAccountName) /pass:$($storageAccountKeys[0].Value)")
您可以使用 list 参数验证 cmdkey 实用程序是否已存储存储帐户的凭据:
cmdkey /list
如果您的 Azure 文件共享的凭据已成功存储,预期输出如下(列表中可能存储了其他密钥):
Currently stored credentials:
Target: Domain:target=<storage-account-host-name>
Type: Domain Password
User: AZURE\<your-storage-account-name>
您现在应该能够挂载或访问共享,而无需提供额外的凭据。
推荐阅读
- apache - Htaccess 规则被覆盖
- spring-boot - spring-cloud-stream kafka 如何使用循环策略生成消息?
- npm - 重命名一个 npm 模块,对名称进行细微更改 => “包名太相似”
- python - Numpy 通过套接字串接导致解码错误
- python - Python 数据错误:ValueError:int() 的文字无效
- javascript - HTMLUnit:ReferenceError:未定义“$”
- text - Spacy TextCategorizer 使用的 CNN 可以在哪里配置?
- node.js - 在 cPanel 上托管一个不和谐的机器人
- css - 带有 :before 和 z-index 的边界半径之外的 CSS 背景
- javascript - 将xml返回到textarea php