1

I am attempting to establish a sftp connection using paramiko and verify the ssh connection using a host key fingerprint. The host key is provided to me and is in the format:

SHA256:lZ4rtJE62SWt6P+AS5q0+JZrpG/5Mejdm7sL/cvy4A8=

import paramiko
from base64 decodebytes

fingerprint = b'lZ4rtJE62SWt6P+AS5q0+JZrpG/5Mejdm7sL/cvy4A8='
host_key = paramiko.RSAKey(data=decodebytes(fingerprint))

This results in: UnicodeDecodeError:'utf-8' codec can't decode byte 0x8a in position 2: invalid start byte

Connecting using FileZilla I can see the Hostkey algorithm is ssh-rsa 2048.

Can anyone help me create the RSAKey from the provided SHA256 fingerprint so I can connect and verify the host using the following:

ssh = paramiko.SSHClient()
ssh.get_host_keys().add(hostname=my_host_name, keytype=host_key.get_name(), key=host_key)
ssh.connect(hostname=my_host_name, port=22, username=my_user_name, pkey=my_private_key)
sftp = ssh.open_sftp()

A couple of things to note:

  1. I have asked for the hosts public key to use instead but this is not forthcoming. Apparently due to the SFTP server being hosted as an 'AWS Transfer Family' service which only provides the server host key.
  2. I cannot use pysftp due to organisation policy (it's too old).
Mark
  • 41
  • 4
  • 1
    You can't transform a fingerprint into an RSA key. You **can** calculate the fingerprint for a given host key and check that it matches the expected fingerprint. – larsks Feb 03 '22 at 13:50
  • Thank you both. – Mark Feb 04 '22 at 18:34

0 Answers0