Olá pessoal,
Recentemente precisei criar uma conta de usuário em vários servidores linux no azure, a conta era local e seria utilizada por um serviço para administração remota e teria a senha em formato de certificado RSA. No lugar de fazer o processo em cada servidor manualmente, inicialmente havia pensado em fazer um laço foreach e conectar em cada servidor, copiar o certificado da credencial e conceder os privilégios, mas ai lembrei que há uma extensão no azure chamada VMAccess e a versão para linux não só redefine as configurações do SSHD, mas também pode criar novos usuários, seja com senha ou com certificado RSA.
Primeiro utilizei o ssh-keygen para gerar a chave da credencial:
ssh-keygen -t rsa -b 2048 -f .\svc_application
Em seguida utilizei o laço foreach para iterar na lista de VMs que selecionei. Em seguida crio uma hashtable com os parametros do comando usando uma técnica chamada Splatting que ja expliquei em um artigo anterior, isso melhora a leitura do script e facilita o troubleshooting.
foreach ($VM in @(Get-AzVM | Out-GridView -OutputMode Multiple)) {
$AzVMExtension = @{
ResourceGroupName = $VM.ResourceGroupName
VMName = $VM.Name
Location = $VM.Location
Name = 'VMAccessForLinux'
Publisher = 'Microsoft.OSTCExtensions'
ExtensionType = 'VMAccessForLinux'
TypeHandlerVersion = '1.5'
Verbose = $true
Settingstring = '{}'
ProtectedSettingString = '{
"username": "svc_application",
"ssh_key": "ssh-rsa 6A94Ecd8WWLDfs7j1mnBILRElfP1viWN6rJ/T9WWfNe6ZMq7XKtFGchtHBGXeT5ZSCmIOurm5rQp6F4BHGrRRmRcP/ANDJrvlNH5N7lim6aWuyy+yuw/28BAeCyZMxTquJq/vc34fcFZLkclqeLQhAkY1GueGD7kCXJ/jmEyHRt5AIANDbHL07p+6YAF/DB6ANS9pTboQOfuvNVmW6pgG8duyajHjjS5EwTbIyfRaWNlu1E3j9uUzjglIYbxjBW4B+bZXUOfVoFoKfVARpHfsP5AFNSyh5WuPkU9bQzpUGYB/JQ1ZfyCZr+5EOZ7XOAzlApEFHaOGUA055dljxEelum6B/aI8meA+kAis1rqFRHALvC8zAF1"
}'
}
Set-AzVMExtension @AzVMExtension
}
Dúvidas? Sugestões? Comente!
Até a próxima!
23 Comments
up
up
Hello, just wanted to tell you, I liked this blog post. It was practical. Diandra Flory Handbook
Great website! I am loving it!! Will come back again. I am taking your feeds also Pennie Olin Haymes
Merci Caroline. Les mots qui me paraissent puissants dans cet article sont : Amberly Mattias Inessa
beautiful as described. Packed well, and shipped very fast. Excellent Transaction Casandra Town Graig
Wonderful blog! I found it while browsing on Yahoo News. Micheline Brew Nicholas
Thanks for your personal marvelous posting! I actually enjoyed reading it, you may be a great author. I will remember to bookmark your blog and will often come back from now on. I want to encourage you to continue your great writing, have a nice weekend!| Cesya Lief Sheeb
I like looking through an article that will make men and women think. Also, thanks for permitting me to comment! Shannen Tome Esta
I needed to send you that little remark in order to say thanks a lot the moment again with your remarkable principles you have shown at this time. It has been really extremely open-handed with you to allow freely what a number of us could have advertised as an electronic book to generate some cash for themselves, even more so considering that you could possibly have tried it if you ever considered necessary. Those techniques in addition acted to provide a great way to understand that someone else have the identical desire just like my personal own to learn way more in respect of this condition. I am sure there are a lot more pleasurable occasions up front for folks who discover your blog post. Camellia Curr Hyacinth
Needed to write you that very little remark to finally say thanks a lot once again for your personal splendid basics you have discussed on this website. It is simply extremely generous with you to provide without restraint exactly what a lot of people might have made available as an e-book to make some cash for themselves, most importantly considering the fact that you could possibly have done it if you decided. The good ideas in addition worked as a great way to be certain that most people have a similar passion similar to my own to figure out a little more in respect of this matter. I know there are thousands of more fun opportunities up front for individuals who start reading your blog. Farah Dag Emmalynn
What happened to the courthouse that was in the Ridgeway shots? Was it just a front? Ariela Clayson Caddaric
Having read this I thought it was very informative. I appreciate you finding the time and effort to put this informative article together. I once again find myself spending a significant amount of time both reading and leaving comments. But so what, it was still worth it! Nancy Emmanuel Micco
Whoah this weblog is great i like studying your articles. Keep up the good work! You already know, a lot of people are searching around for this information, you could aid them greatly. Hana Cullin Tedmann
Your style is really unique compared to other people I have read stuff from. Thanks for posting when you have the opportunity, Guess I will just bookmark this page. Leta Reinald Dorothee
Excellent write-up. I definitely appreciate this website. Keep it up! Eleni Klement Sihunn
Very interesting info!Perfect just what I was searching for! Jordanna Byron Alves
Say, you got a nice article post. Really thank you! Keep writing. Teriann Hollis Prospero
Everything is very open with a clear clarification of the challenges. It was truly informative. Your site is very useful. Thank you for sharing! Constantia Jaime Novelia
Processed living is typically manager in chemical additives, hormones, sugar, liveliness, debilitated well-to-do, and calories, all of which can adversely potency persdus.boaplos.nl/gezond-lichaam/wilfried-de-jonghe-boek.php your bananas acuity and outlook. It can step on it you empathy bushed, expanded, and crotchety, and exacerbate symptoms of concavity, eruption, inspect, and other balmy haleness concerns. It can also nag your waistline. Drusy Etienne Abdella
This is what you could look like. LaughNews.com Very nice post. I just stumbled upon your weblog and wanted to say that I have truly enjoyed browsing your blog posts. After all I will be subscribing to your rss feed and I hope you write again soon! Dion Winny Clevey
Hi there. I found your blog by means of Google while looking for a comparable subject, your website came up. It appears to be good. I have bookmarked it in my google bookmarks to come back then. Michal Bartie Lorianne
Nice read, I just passed this onto a colleague who was doing some research on that. And he just bought me lunch because I found it for him smile Thus let me rephrase that: Thank you for lunch! Shirleen Granthem Bilow