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 on this site, held on your device. The app adds 632 more: 1,510 commands and 120 fix flows, searchable with no connection. Free to install, no ads (some content is a one-time purchase).

Get it free on the App Store