Skip to content

Instantly share code, notes, and snippets.

@agolomoodysaada
Last active January 26, 2024 03:09
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save agolomoodysaada/1ad50f3ca4efd32d543dd9b66da12eff to your computer and use it in GitHub Desktop.
Save agolomoodysaada/1ad50f3ca4efd32d543dd9b66da12eff to your computer and use it in GitHub Desktop.
Azure Virtual Machine Scale Set(VMSS) Reset SSH KEY
az vmss extension set \
--vmss-name <vmss-name> \
-g <resource-group> \
-n VMAccessForLinux \
--publisher Microsoft.OSTCExtensions \
--version 1.4 \
--protected-settings "{\"username\":\"deploy_user\", \"ssh_key\":\"$(cat ~/.ssh/id_rsa.pub)\"}"
# Upgrade ALL instances in the scale set with the new key
az vmss update-instances --instance-ids '*'
-n <vmss-name>
-g <resource-group>
@flyinprogrammer
Copy link

az vmss update-instances --instance-ids '*'
                         -n <vmss-name>
                         -g <resource-group>

should be

az vmss update-instances --instance-ids '*' \
                         -n <vmss-name> \
                         -g <resource-group>

you might also consider updating deploy_user to <deploy-user> as well.

mostly, thanks for creating this gist, it saved me a lot of time reading MS documentation.

@prune998
Copy link

prune998 commented Aug 20, 2019

thanks too ! spend almost one hour to be able to SSH into this !@# VMSS thing...
Great job !

@VenkataRKC
Copy link

Btw does this "update-vmss-ssh-key.sh" update the existing key which was already set with an extension ?. Basically i have added the ssh key with the commands mentioned in update-vmss-ssh-key.sh ...now i want to change the ssh key ...shall i follow the same steps mentioned with a different pub key ?

@azach2878
Copy link

Doesn't work! everytime I try this give me an error /home/user/.ssh/id_rsa.pub: No such file or directory

@fredgate
Copy link

fredgate commented Aug 4, 2023

Next how to remove the SSH key ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment