0

Trying to connect to sftp server using ssh key

#!/bin/python

import pysftp
with pysftp.Connection(host='sftp.myserver.com', username='stg', private_key='/Users/joel/.ssh/id_rsa_sftp', private_key_pass='') as sftp:

And I am getting

raise SSHException("No hostkey for host %s found." % host)
Joel Divekar
  • 187
  • 1
  • 4
  • 19
  • See [Verify host key with pysftp](https://stackoverflow.com/q/38939454/850848#43389508). – Martin Prikryl Oct 31 '19 at 08:35
  • this is know issue with pysftp = 0.2.9 and so i moved to [paramiko](https://www.paramiko.org/) – Joel Divekar Nov 01 '19 at 06:49
  • Possible duplicate of ["Failed to load HostKeys" warning while connecting to SFTP server with pysftp](https://stackoverflow.com/questions/56521549/failed-to-load-hostkeys-warning-while-connecting-to-sftp-server-with-pysftp) – Martin Prikryl Nov 06 '19 at 07:09

1 Answers1

0

You could use my pysftp fork from github and add auto_add_key=True
This will add the host key on the first connection to your known_hosts file...

import pysftp

with pysftp.Connection('hostname', username='me', password='secret', auto_add_key=True) as sftp:
    with sftp.cd('public'):             # temporarily chdir to public
        sftp.put('/my/local/filename')  # upload file to public/ on remote
        sftp.get('remote_file')         # get a remote file
Fabian
  • 1,130
  • 9
  • 25