Skip to content

Latest commit

 

History

History
87 lines (64 loc) · 1.92 KB

azure-cli.md

File metadata and controls

87 lines (64 loc) · 1.92 KB

Azure CLI

Installation

https://docs.microsoft.com/en-us/cli/azure/install-azure-cli

Mac OS

$ brew install azure-cli
$ az login

Adding and deleting users

If you messed up your current user, you can create a new one - it will have rights to run sudo, so you'll be able to fix stuff with it:

$ az vm user update \
--resource-group YOUR-RESOURCE-GROUP \
--name YOUR-VM-NAME \
--username petya \
--ssh-key-value ~/.ssh/YOUR-VM-NAME.pub

When you are done fixing stuff, you can delete that user:

$ az vm user delete \
  --resource-group YOUR-RESOURCE-GROUP \
  --name YOUR-VM-NAME \
  --username petya

Fixing sudoers

If you messed up your /etc/sudoers.d/whatever and getting errors like:

>>> /etc/sudoers.d/90-cloud-init-users: syntax error near line 5 <<<
sudo: parse error in /etc/sudoers.d/90-cloud-init-users near line 5
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin

Lower the permissions to the sudoers.d and its contents, so you could edit that file:

$ az vm run-command invoke \
-g YOUR-RESOURCE-GROUP -n YOUR-VM-NAME \
--command-id RunShellScript \
--scripts "chmod 777 /etc/sudoers.d"

$ az vm run-command invoke \
-g YOUR-RESOURCE-GROUP -n YOUR-VM-NAME \
--command-id RunShellScript \
--scripts "chmod 777 /etc/sudoers.d/*"

Fix the error (back on the server via SSH):

$ nano /etc/sudoers.d/whatever

Put permissions back:

$ az vm run-command invoke \
-g YOUR-RESOURCE-GROUP -n YOUR-VM-NAME \
--command-id RunShellScript \
--scripts "chmod 440 /etc/sudoers.d/*"

$ az vm run-command invoke \
-g YOUR-RESOURCE-GROUP -n YOUR-VM-NAME \
--command-id RunShellScript \
--scripts "chmod 440 /etc/sudoers.d"