Q: paramiko/SSH/ how to get a remote host_key
Charles_hans
charles_hans at yahoo.com
Wed Jan 30 16:40:35 EST 2008
Thank you, Guilherme. I was running demo_sftp.py included in paramiko
download.
It seems that '.ssh/known_hosts' should be the path of a key file on my
working directory on local PC. (Right?) I replaced this with 'test_rsa.key'
in C:\paramiko-1.7.2\demos and this did not generate error. But the returned
host_keys is empty. I traced the code to 'hostkeys.py' and found that the
line
e = HostKeyEntry.from_line(line)
always retuned None. This means that my remote host name should have been in
this key file. (Right?)
I am very new to paramiko. How to create such a key file (with my remote
host name)? Should I also load this key file into the remote server? Please
advise. Thanks!
Charles
1/30
2008/1/30, Charles_hans <charles_hans at yahoo.com>:
>
> I tried to get what host_key has been aquired after AutoPolicy is set. I
> added the following code just before client.close() in rosty's final code:
>
> try:
> host_keys =
> paramiko.util.load_host_keys(os.path.expanduser('~/.ssh/known_hosts'))
> except IOError:
> try:
> host_keys =
> paramiko.util.load_host_keys(os.path.expanduser('~/ssh/known_hosts'))
> except IOError:
> print '*** Unable to open host keys file'
>
> I still got 'Unable to open host keys file'. Can you tell me how to get
> the
> remote host_key under this situation? Thanks!
>
> Charles
> 1/30/2008
Hey Charles,
If you take a look on your code, you will see that you are catching
IOError. So the problem you are noticing is related to I/O failing
such as non-existent file. Be sure to check if '~/.ssh/known_hosts'
exists, if the first try fails, check if "~/ssh/known_hosts" exists
then (since you are trying to access that file).
Cheers,
> by rosty Jan 21, 2008; 08:43am :
>
> Thank you! Now it works and the code looks like this:
>
> import paramiko
> import base64
> from paramiko import AutoAddPolicy, SSHClient
>
> client = paramiko.SSHClient()
> client.set_missing_host_key_policy(AutoAddPolicy())
> client.connect('hostIP', username='uname', password='pass')
> stdin, stdout, stderr = client.exec_command('ls')
> for line in stdout:
> print '... ' + line.strip('\n')
>
> client.close()
--
View this message in context: http://www.nabble.com/Q%3A-paramiko-SSH--how-to-get-a-remote-host_key-tp14996119p15192764.html
Sent from the Python - python-list mailing list archive at Nabble.com.
More information about the Python-list
mailing list