How can I get the ssh host key for a new Azure Linux VM created using PowerShell? -
if create azure linux vm using powershell, how can new ssh host key, can install in local ssh/putty? preferably solution powershell code.
the rsa, dsa, ecdsa, , ed25519 keys generated on first boot, , available in boot diagnostics log.
if don't catch on first boot, don't think it's listed anywhere else in portal. there's 1 feasible, secure option of can think recovering fingerprint already-deployed vm.
- create new vm.
- attach vhd of vm need fingerprint.
- verify connection new vm using fingerprint in boot diagnostics.
check fingerprint generated
/etc/ssh/ssh_host_rsa_key.pub
file on other disk.ssh-keygen -lf /{path}/ssh_host_rsa_key.pub
you may need add -e md5
switch if need hexadecimal encoded md5 hash.
powershell
to boot diagnostics data via powershell:
get-azurermvmbootdiagnosticsdata -resourcegroupname examplegroup -name testlab -linux
connecting putty
azure computes host key fingerprints base64 encoded string of sha-256 hash of public key. when attempt connect using putty, presents fingerprint hexadecimal encoded string of md5 hash of public key.
fortunately, azure lists full public key in boot diagnostics log, says begin ssh host key keys
in second image. that, can manually compute fingerprint presented putty.
c#
static string computemd5fingerprintfrombase64(string encoded) { // convert base64 string byte array. byte[] pub = convert.frombase64string(encoded); // compute md5 hash. hashalgorithm md5 = md5.create(); byte[] hash = md5.computehash(pub); return bitconverter.tostring(hash).replace('-', ':'); }
Comments
Post a Comment