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.

key generation key listing

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.

  1. create new vm.
  2. attach vhd of vm need fingerprint.
  3. verify connection new vm using fingerprint in boot diagnostics.
  4. 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

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -