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
Related commands
- aws ssm start-sessionSession Manager shell
- az vm listList Azure VMs
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