該種方式是推薦的進行Automation認證的方式,好處在於安全性高,過時時間由本身控制,很差的地方在於你們在Windows上要生成證書比較麻煩,並且必須上傳到Azure management和Automation,shell
Automation須要兩個文件:.pfx證書用於用戶自動化端鏈接Azure,.cer文件,Azure管理端證書文件,這兩個文件必須互相匹配。windows
對於建立證書,我的比較推薦的辦法,或者我喜歡用的方法,就是利用開源的openssl工具,幾個命令快速搞定,我在個人本機安裝的是Ubuntu on windows,很是方便,你們感興趣能夠參考:安全
http://cloudapps.blog.51cto.com/3136598/1761954服務器
通常的Linux上都自帶了OpenSSL,若是沒有須要安裝一下,固然你用Windows的也能夠,首先第一步,生成服務器端的X509文件和key,記住在此處生成的密碼:app
$ openssl req -x509 -days 365 -newkey rsa:1024 -keyout server-key.pem -out server-cert.pemide
而後經過pem文件,key,利用openssl生成Azure automation須要的pfx文件:工具
$ openssl pkcs12 -export -in server-cert.pem -inkey server-key.pem -out mycert.pfxspa
最後,經過pem文件生成Azure服務器管理端須要的x.509的cer文件:命令行
$ openssl x509 -inform pem -in server-cert.pem -outform der -out mycert.cerorm
你也可使用Windows的makecert工具生成Azure須要的cer和pfx文件。
首先下載Windows SDK for Windows 10或者windows 8:
https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk
https://developer.microsoft.com/en-us/windows/downloads/windows-8-sdk
安裝完成後在program Files下的Windows kits下能夠看到makecert命令行,使用makecert生成cer文件:
makecert.exe -sky exchange -r -n "CN=AzureAutomation" -pe -a sha1 -len 2048 -ss My "AzureAutomation.cer"
生成cer文件之後,咱們可使用Powershell生成pfx文件,請用管理員權限打開Powershell:
#myautomation是pfx的密碼,在導入到Azure Automation時須要使用
$MyPwd = ConvertTo-SecureString -String "myautomation" -Force –AsPlainText
# "AzureAutomation"是certificate的名字,在第一步生成的
$AzureCert = Get-ChildItem -Path Cert:\CurrentUser\My | where {$_.Subject -match "AzureAutomation"}
#導出生成pfx文件
Export-PfxCertificate -FilePath C:\AzureAutomation.pfx -Password $MyPwd -Cert $AzureCert
不管你是使用Linux仍是Windows生成證書,必須確保你有一個X509的cer證書和一個帶密碼的pfx證書,前者用於上傳到management證書,pfx上傳給runbook的資產做爲受權憑證。
上傳cer文件到Azure的管理證書,登錄Azure的portal,選擇設置,管理證書,而後再下方選擇"上載",選擇你在上述步驟中生成的.cer並選擇肯定:
打開自動化管理帳號,選擇資產,並在下方菜單中選擇添加設置:
在添加類型中選擇添加憑據,在憑據類型中選擇證書,
選擇在上述步驟中生成的pfx文件,輸入密碼,而後肯定,完成上傳:
在後續章節中介紹如何使用憑證進行驗證使用。