Verify Mikrotik's SSH public key fingerprint

I’ve successfully set the SSH login to MikroTik using Ed25519 key and it works as expected. But I don’t know how to verify the fingerprint of the MikroTik’s public key.

According to the MikroTik SSH documentation the keys are exported in PKCS8 format.

According to this old post calculating the fingerprint can be done using ssh-keygen and file with public key (test_rsa_pub.pem) exported and downloaded from MikroTik.

ssh-keygen -f test_rsa_pub.pem -i -m PKCS8 | ssh-keygen -l -f - -E md5

NOTE: In this case, Windows version of ssh-keygen does NOT work: it either produces empty output, hangs or reports “this is not a public key file”. If you work under Windows, install WSL and try it from there.

This works for RSA keys, but not for Ed25519 - ssh-keygen fails with error “unsupported pubkey type 1087”. Which appears to be a bug that was supposed to be fixed, but in OpenSSH 9.6p1 it’s obviously still present.

Does anybody have a clue, how to easily get the SSH key fingerprint for Ed25519 in Mikrotik environment? Aside the very obvious “connect over safe line first and mark the fingerprint as trusted.”.

This is something I really really (pretty please) wish they would implement. The fingerprint should be readily available in both gui and cli interfaces.

I also could not get ssh-keygen to work with the Mikrotik Ed25519 host key exports. They dont recognize them as key files. Also I cannot import Ed25519 key files made with ssh-keygen into Mikrotik, it gives a “unable to load key file” error.

Just for reference, I was able to use ssh-keygen to verify the fingerprints of Mikrotik generated RSA host keys.

Export on Mikrotik:

[MikroTik] /ip/ssh> export-host-key key-file-prefix=test
11:23:44 echo: ssh,critical SSH host keys exported to test_rsa.pem
[MikroTik] > /file/print
 # NAME                                                                              TYPE             SIZE LAST-MODIFIED
 2 test_rsa.pem

On local computer:

$ scp user@mikrotik:test_rsa.pem .
test_rsa.pem                                                                                      100% 1704   232.6KB/s   00:00

$ chmod 0600 test_rsa.pem

# create an openssh public key 
# this would match the entry in known_hosts
$ ssh-keygen -y -f test_rsa.pem > test_rsa_ssh.pub
$ cat test_rsa_ssh.pub
ssh-rsa AAAAB3NzaC1yc2EAAAABAwAAAQEAxB1/
<lines redacted>
QauPheFrso+QNNrpOYQ+OHlKkjAwom2UZew6Sw==

# show fingerprint that you would see during new SSH connection
$ ssh-keygen -lf test_rsa_ssh.pub
2048 SHA256:Oqn<characters redacted>mgs no comment (RSA)

It would be great to have openssh style fingerprints accessable from the cli to verify you are connecting to the right place. Now we are just going on faith.

Putty’s event log shows the fingerprint of the server you’re connecting to, if that’s helpful.

Yes, it’s understood that ssh clients display the fingerprint, at least on first connection. What we are looking for is a way to display that fingerprint on the Mikrotik device (or at least derive the fingerprint from something on it) so we can verify it is the thing we are connecting to, and not some man-in-the-middle.

I can get it to work for RSA host certificates (with some work) but not Ed25519.

Here is an explanation of Mikotiks ed25591 host key files and the issues manipulating them. Hold on because this will take a while.

Generate a new ed25591 host certificate on your Mikrtik router:

[MikroTik] > /ip/ssh/print
                      ciphers: auto
           forwarding-enabled: no
  always-allow-password-login: no
                strong-crypto: yes
                host-key-size: 2048
                host-key-type: ed25519

[MikroTik] > /ip/ssh/regenerate-host-key
This will regenerate current SSH host keys, yes? [y/N]:
y
16:19:41 echo: ssh,critical SSH host key regenerated!

[MikroTik] > /ip/ssh/export-host-key key-file-prefix=mikrotik
16:20:42 echo: ssh,critical SSH host keys exported to mikrotik_ed25519

[johns@MikroTik] > /file print
 # NAME                                                                                                                                TYPE             SIZE LAST-MODIFIED
 1 mikrotik_ed25519_pub.pem  pem file         113 2025-07-10 16:20:42
 2 mikrotik_ed25519.pem      pem file         119 2025-07-10 16:20:42
 

[MikroTik] > :put [/file/get mikrotik_ed25519.pem contents]
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIP/6e1tHq6xA5WbiWULDCeakQdzIsNEzcRG0rZFiQbzs
-----END PRIVATE KEY-----

[MikroTik] > :put [/file/get mikrotik_ed25519_pub.pem contents]
-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEAmRlfVmthnWcRbWGIuZZuFACG5bIXO/M+MnCZnmirMHc=
-----END PUBLIC KEY-----

Transfer this key file over to a computer to do more analysis. I used one running Debian Bookworm.

This private host key is in pkcs#8 format and PEM encoding. This is similar to a key created with openssl using
openssl genpkey -algorthm ed25519 -out mikrotik_ed25519.pem

To create an ssh fingerprint like will be reported when we first connect we would ordinarily use ssh-keygen from OpenSSH,
but it does not recognize this key. It seems that until recently OpenSHH did not fully support ed25519 type keys.

see:
https://bugzilla.mindrot.org/show_bug.cgi?id=3195 Bug 3195 - ssh-keygen unable to convert ED25519 public keys
fixed in openssh-9.6

I have an earlier version, so until I can upgrade to Debian testing Ill have to find a way.

$ sudo apt-cache policy openssh-client
openssh-client:
  Installed: 1:9.2p1-2+deb12u5

OpenSSH ssh-keygen fails to recognize this host key file.

$ ssh-keygen -l -f mikrotik_ed25519.pem
mikrotik_ed25519.pem is not a key file.

I found a very handy bash script that will do the conversion until then in this conversation (its not really attributed, so I dont know who to thank):

https://security.stackexchange.com/questions/267711/how-can-i-convert-an-ed25519-key-in-pkcs8-to-openssh-private-key-format

eddsa-ssl-to-ossh.sh

#!/bin/sh

set -euf

ssl_priv=$(cat ${1:+"$1"})

pub64=$(echo "$ssl_priv" | openssl pkey -pubout -outform der 2>/dev/null | dd bs=12 skip=1 status=none | base64)

test "$pub64" || { echo "Cannot get public key" >&2; exit 1; }

priv64=$(echo "$ssl_priv" | grep -v '^-' | base64 -d | dd bs=16 skip=1 status=none | base64)

echo '-----BEGIN OPENSSH PRIVATE KEY-----'

{
    printf openssh-key-v1'\000\000\000\000\004'none'\000\000\000\004'none'\000\000\000\000\000\000\000\001\000\000\000'3
    printf '\000\000\000\013'ssh-ed25519'\000\000\000 '
    echo $pub64 | base64 -d
    printf '\000\000\000'
    printf '\210\000\000\000\000\000\000\000\000'
    printf '\000\000\000\013'ssh-ed25519'\000\000\000 '
    echo $pub64 | base64 -d
    printf '\000\000\000@'
    echo $priv64| base64 -d
    echo $pub64 | base64 -d
    printf '\000\000\000\000\001\002\003\004\005'
} | base64

echo '-----END OPENSSH PRIVATE KEY-----'

Manipulate the host key file

$ chmod 0600 mikrotik_ed25519.pem
$ bash ./eddsa-ssl-to-ossh.sh mikrotik_ed25519.pem > mikrotik_ed25519.openssh.pem
# this is now in OpenSSH format
$ cat mikrotik_ed25519.openssh.pem
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZWQyNTUx
OQAAACCZGV9Wa2GdZxFtYYi5lm4UAIblshc78z4ycJmeaKswdwAAAIgAAAAAAAAAAAAAAAtzc2gt
ZWQyNTUxOQAAACCZGV9Wa2GdZxFtYYi5lm4UAIblshc78z4ycJmeaKswdwAAAED/+ntbR6usQOVm
4llCwwnmpEHcyLDRM3ERtK2RYkG87JkZX1ZrYZ1nEW1hiLmWbhQAhuWyFzvzPjJwmZ5oqzB3AAAA
AAECAwQF
-----END OPENSSH PRIVATE KEY-----

# change permissions to be restrictive
$ chmod 0600 mikrotik_ed25519.openssh.pem
#
# OpenSSH can now work with this file and give the fingerprint
# this matches the fingerprint from the first SSH session
$ ssh-keygen -lf mikrotik_ed25519.openssh.pem
256 SHA256:nU+v64Ko6LnBh+ijYuWprosuHmtDQ+u+hgJ3+slLYhI  (ED25519)
# Create an OpenSSH public key from the private key
$ ssh-keygen -y -f mikrotik_ed25519.openssh.pem > mikrotik_ed25519.openssh.pub.pem
# This public key matches the enty in known_hosts
$ cat mikrotik_ed25519.openssh.pub.pem
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJkZX1ZrYZ1nEW1hiLmWbhQAhuWyFzvzPjJwmZ5oqzB

First attempt to SSH with new key. Note this matches the fingerprint above.

$ ssh mikrotik@192.168.1.1
The authenticity of host '192.168.1.1 (192.168.1.1)' can't be established.
ED25519 key fingerprint is SHA256:nU+v64Ko6LnBh+ijYuWprosuHmtDQ+u+hgJ3+slLYhI.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.1.1' (ED25519) to the list of known hosts.

known_hosts matches OpenSSH public key above.

$ grep "192\.168\.1\.1 " ~/.ssh/known_hosts
192.168.1.1 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJkZX1ZrYZ1nEW1hiLmWbhQAhuWyFzvzPjJwmZ5oqzB3

Do you realize, that this post of yours is just AI bullsh*t?

It’s an AI summary spam of the problem from stackexchange, including the links from my original post and pieces of solution from other processes, that are just vaguely related to this topic.

If you can’t verify the relevance of the solution given to you by AI, do NOT post it!

It should NOT be taken seriously at all, just because it recommends to download the unencrypted PRIVATE key from MikroTik, printing out this unencrypted private key into the console output, completely ignoring the fact, that the key is generated y MikroTik device, not OpenSSL and other ***.

Wow, not the response I expected.

I took all the steps above on the router in my home lab, such as it is. I included all of the steps and information so that anyone can recreate it themselves. Of course I would never print out a Private Key or move it around unencrypted on production machines, but this was just doing a proof of concept. I was trying to be transparent and quick.

As soon as I typed out all the steps I recreated the host keys on this machine and moved on to the next interesting issue.

No “AI” was used in the writing of this. I did do traditional searches on DuckDuckGo. I think all of the links included are relevant to the discussion. I did repeat the report of the bug in ssh-keygen as a way of explanaition for anyone who didnt read the entire thread, and hopefully I will have a chance to test the backport later today. This should remove the need for the “AI summary spam of the problem from stackexchange”.

I think all of us would feel better if Mikrotik would supply an OpenSSH style fingerprint of the Host Key, but until then anyone can follow the steps above to create the fingerprint themselves on their computer and verify they are connecting where they think they are.

There are open questions in the proceedure about how to transfer the Host Key export file safely. I was on a serial console and had the luxury of printing, copy and paste. You could also email to yourself, ftp or just connect ssh to scp it and verify after the fact.

I hope people find the process above useful.

Okay, point taken. The thing is, that when I asked Copilot about the same thing, I got almost exactly the same answer as you posted. If that was not how you did it, I apologize for my rage vent - I see this far too often and it makes me simply mad.

TBH, yes I found that script before, but with emphasis on the “simple way” from my original post, I skipped this and other methods like "restore the binary backup of MikroTik to virtual machine, because connecting there could be considered as a safe link from where you get the public key.

Another method is to use another tool for example SSHPK, but that again requires install Linux or WSL, install node.js, install package… blah blah… yeah, possible workaround for sure, but highly impractical.

I believe there should be simpler methods of verifying the public key for remote connection to MikroTik device: if you can simply say “yeah, this public key is probably fine” in less than a second and skip the security part or have it annoyingly long with workaround steps then after few rounds of this you find out it’s just not worth the time and effort…

Again, really frustrating if you ask me.

I was able to try a newer release of openssh-client including ssh-keygen on Debian bookworm-backports this morning and it now seems to be working correctly with ed25519 keys.

This is good because you now dont need that questionable bash script above from stackexchange.

 $ sudo apt-cache policy openssh-client
openssh-client:
  Installed: 1:10.0p1-5~bpo12+2
  Candidate: 1:10.0p1-5~bpo12+2

# create SSH style fingerprint directly from ed25519 openssl style host key
$ ssh-keygen -l -f mikrotik_ed25519.pem
256 SHA256:nU+v64Ko6LnBh+ijYuWprosuHmtDQ+u+hgJ3+slLYhI no comment (ED25519)

# create SSH style public key
$ ssh-keygen -y -f mikrotik_ed25519.pem
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJkZX1ZrYZ1nEW1hiLmWbhQAhuWyFzvzPjJwmZ5oqzB3

how is this still not solved? why is there neither a GUI or CLI option to simply show the fingerprint
This is the first time i'm connecting to a known and previously used mikrotik client and have a SSH fingerprint mismatch from what was saved. With all of the security issues lately i'm genuinely unsure if there is a man-in-the-middle scenario with SSH (yes its restricted and not open to the internet, but i'm not physically there plugged into it)

Cmon mikrotik this is ridiculous, give us an option to display the fingerprint locally on the routerOS device. This seems like common sense basic security stuff yeah?

the post before mine doesn't work on Windows. It just errors out with 'is not a key file' and apparently its because the ssh-keygen version is largely out of date

I was looking for a clean simple 1 liner method but apparently there is none unless you're on linux/mac
Until MikroTik implements a simple 'show fingerprint' method here is a Claude written script that will generate the fingerprint from the [prefix]_rsa_pub.pem file

&{function s($b){@(0,0,($b.Length -shr 8),($b.Length%256))+$b}
$t=Read-Host 'Type (rsa/ed25519)';$d=[Convert]::FromBase64String(((gc (Read-Host 'File'))-notmatch'-')-join'')
$k=if($t-eq'rsa'){(s $d[-3..-1])+(s $d[(28+4*($d[1]-eq130))..($d.Length-6)])}else{s $d[12..43]}
'SHA256:'+[Convert]::ToBase64String([Security.Cryptography.SHA256]::Create().ComputeHash([byte[]]((s ([byte[]][char[]]"ssh-$t"))+$k))).TrimEnd('=')}

Open Powershell in the folder you downloaded the _pub.pem file, paste the above and it'll ask for RSA/ED25519 format and the filename and then give you the fingerprint.

Compare it against what is shown with ssh-keyscan [IP ADDRESS] | ssh-keygen -lf -