@jpmens Reading over /usr/src/usr.bin/ssh/ssh-keygen.c it looks like the officia...
Tim Chase @gumnos@bsd.cafe
Reading over /usr/src/usr.bin/ssh/ssh-keygen.c it looks like the official method is to open the file and attempt a blank password. If that works, then you know it, um, has a blank password.
Digging further into the source, you might be able to get away with opening the private key-file, decoding the uuencoded¹, peeling off a header, and then checking of the ciphername and key-derivation function-name are both "none" for a passwordless key. So you should be able to do
$ [ "$(sed -e 1d -e '$d' $PRIVATEKEYFILE | b64decode -r | dd skip=19 bs=1 count=4 2>/dev/null)" = "none" ] && [ "$(sed -e 1d -e '$d' $PRIVATEKEYFILE | b64decode -r | dd skip=27 bs=
1 count=4 2>/dev/null)" = "none" ] && echo no password
for a default SSH $PRIVATEKEYFILE with the "-----BEGIN OPENSSH PRIVATE KEY-----" line rather than an OpenSSL format PEM file.
⸻
¹ it doesn't seem to like `uudecode -r` on that content despite the internal function being called private2_uudecode; instead it appears to be b64 encoded:
$ sed -e 1d -e '$d' $PRIVATEKEYFILE | uudecode -r
whines about out-of-range values while
$ sed -e 1d -e '$d' $PRIVATEKEYFILE | b64decode -r | hexdump -C
returns expected content