I am aware that Verify host key with pysftp has reply for this post that every other post seem to refer but I am still unable to connect using hostkey after trying considerable amount of time before asking.
What am I doing?
I have this
Server host key fingerprints
SHA-256 = ssh-rsa 2048 TaaZ43VZIRKls7oDx............
MD5 = ssh-rsa 2048 ed:06:b3:16:9f:..................
my code looks like this:
fp_key =b"""TaaZ43VZIRKls7oDx........."""
key = paramiko.RSAKey(data=decodebytes(fp_key))
cnopts = pysftp.CnOpts()
cnopts.hostkeys.add(hostname="host",keytype='ssh-rsa', key=key)
sftpConnect = pysftp.Connection(host="host", username="username", password="password", cnopts=cnopts)
Error I am getting:
File "C:\Program Files\Python38\lib\site-packages\paramiko\py3compat.py", line 147, in u
return s.decode(encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa5 in position 4: invalid start byte
Ofcourse my key is not encoded, so it won't be able to decode. So I tried this :
fp_key =b"""TaaZ43VZIRKls7oDx........."""
fp_key = encodebytes(fp_key)
key = paramiko.RSAKey(data=decodebytes(fp_key))
cnopts = pysftp.CnOpts()
cnopts.hostkeys.add(hostname="host",keytype='ssh-rsa', key=key)
sftpConnect = pysftp.Connection(host="host", username="username", password="password", cnopts=cnopts)
Now I am getting this error :
Traceback (most recent call last):
File "sftp_ssh_test.py", line 20, in <module>
key = paramiko.RSAKey(data=decodebytes(fp_key))
File "C:\Program Files\Python38\lib\site-packages\paramiko\rsakey.py", line 62, in __init__
self._check_type_and_load_cert(
File "C:\Program Files\Python38\lib\site-packages\paramiko\pkey.py", line 416, in _check_type_and_load_cert
raise SSHException(err.format(self.__class__.__name__, type_))
paramiko.ssh_exception.SSHException: Invalid key (class: RSAKey, data type: TaaZ43VZIRKls7oDx.........