connecting to sftp server via pysftp with HostKeys

1.3k views Asked by At

I am using pysftp module for connecting to an sftp server. I user the following two commands to skip hostkey file checking:

cnopts = pysftp.CnOpts()
cnopts.hostkeys = None

I still get a warning that says

"Failed to load HostKeys from C:\Users\myusername.ssh\known_hosts. You will need to explicitly load HostKeys (cnopts.hostkeys.load(filename)) or disableHostKey checking (cnopts.hostkeys = None)."

So I would like to load the hostkeys inside the script. But my problem is that I am unable to find the said hostkeys.

I tried connecting to my sftp server via putty but putty terminal closed by itself upon logging in and I don't have any .ssh folder created to see the keys.

Is there any way I can create a hostkey for my sftp server to load inside the script?

1

There are 1 answers

2
python_enthusiast On

So I found out that until you store the hostkey in the host_keys file, you will keep getting the warning. I found out the public key and have saved it inside the host_key. Commented out "cnopts.hostkeys = None" from my script since it hoskeys are being looked up on my machine. No more warnings now.