You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure VM Run-Command管道命令失败,旧版CLI下如何单命令安装Azure CLI?

旧版Azure CLI下通过Run Command单命令安装Ubuntu VM上的Azure CLI

问题背景

使用Azure CLI 2.29.2版本执行az vm run-command invoke,尝试通过管道命令在Ubuntu VM上安装Azure CLI:

az vm run-command invoke --command-id RunShellScript --name trainingVM-1 --resource-group azure-privsec --scripts "curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash"

执行失败,报错:

Could not retrieve credential from local cache for service principal 8bf34d22-7230-47e7-907e-e0df201xxxxx. Please run 'az login' for this service principal.

拆分以下两个命令可成功执行,但需合并为单命令:

az vm run-command invoke --command-id RunShellScript --name trainingVM-1 --resource-group azure-privsec --scripts "wget -O /tmp/file.sh https://aka.ms/InstallAzureCLIDeb"
az vm run-command invoke --command-id RunShellScript --name trainingVM-1 --resource-group azure-privsec --scripts "sudo bash /tmp/file.sh"

解决方案

将两个步骤用&&连接,放在同一个--scripts参数中,确保前一步下载完成后再执行安装脚本:

az vm run-command invoke --command-id RunShellScript --name trainingVM-1 --resource-group azure-privsec --scripts "wget -O /tmp/file.sh https://aka.ms/InstallAzureCLIDeb && sudo bash /tmp/file.sh"

原因说明

旧版Azure CLI在解析带管道的命令时,会错误地将管道后的sudo bash识别为本地CLI需要执行的命令,而非传递给VM的脚本内容,从而触发本地服务主体凭据检查的错误。通过多命令合并的方式,避免管道解析问题,同时保持操作的原子性。

内容的提问来源于stack exchange,提问作者abhinav singh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 00:25:22