JAEN

Cloud

az vm run-command

CautionRun commands in VMs

az vm run-command invoke -g <rg> -n <vm> --command-id RunShellScript --scripts '<cmd>'

Executes inside the VM without SSH/RDP — the rescue path when you've locked yourself out.

Examples

  • az vm run-command invoke -g rg -n web01 --command-id RunShellScript --scripts 'systemctl restart sshd'Repair sshd remotely

Syntax

az vm run-command invoke -g rg -n vm --command-id RunShellScript|RunPowerShellScript --scripts cmd

Before you run it

Runs with full privileges.

Used when you see

Locked out of an Azure VM
3
Repair the guest firewall/SSH via Run Command
See the whole flow →

Related commands

The same reference, with no signal at all

Every command and flow from this site, held on your device and searchable with no connection. Free to install, no ads.

Get it free on the App Store