Hi Experts ,
while i am running following demo ssh script of paramiko -->
It gives error as follows :
Warning (from warnings module):
File "C:\Python26\li b\site-packages\Crypto \Hash\SHA.py", line 6
from sha import *
DeprecationWarn ing: the sha module is deprecated; use the hashlib module instead
Warning (from warnings module):
File "C:\Python26\li b\site-packages\Crypto \Hash\MD5.py", line 6
from md5 import *
DeprecationWarn ing: the md5 module is deprecated; use hashlib instead
Hostname: 10.135.15.41
Username [admin]: root
Warning (from warnings module):
File "C:\Python26\li b\getpass.py", line 88
return fallback_getpas s(prompt, stream)
GetPassWarning: Can not control echo on the terminal.
Warning: Password input may be echoed.
Password for root@10.135.15. 41: alcatel
*** Unable to open host keys file
*** Here we go!
Line-buffered terminal emulation. Press F6 or ^Z to send EOF.
Last login: Mon Dec 13 19:38:31 2010 from 10.135.19.50
*** Caught exception: <type 'exceptions.Att ributeError'>: read
Traceback (most recent call last):
File "C:\Python26\pa ramiko-1.7.4\demos\dem o_simple.py", line 90, in <module>
interactive.int eractive_shell( chan)
File "C:\Python26\pa ramiko-1.7.4\demos\int eractive.py", line 36, in interactive_she ll
windows_shell(c han)
File "C:\Python26\pa ramiko-1.7.4\demos\int eractive.py", line 91, in windows_shell
d = sys.stdin.read( 1)
File "C:\Python26\li b\idlelib\rpc.p y", line 560, in __getattr__
raise AttributeError, name
AttributeError: read
*** EOF ***
Traceback (most recent call last):
File "C:\Python26\pa ramiko-1.7.4\demos\dem o_simple.py", line 101, in <module>
sys.exit(1)
SystemExit: 1
can you tell me what is use of Hostkey and how to overcome this issue?!
while i am running following demo ssh script of paramiko -->
Code:
import base64
import getpass
import os
import socket
import sys
import traceback
import paramiko
import interactive
# setup logging
paramiko.util.log_to_file('demo_simple.log')
# get hostname
username = ''
if len(sys.argv) > 1:
hostname = sys.argv[1]
if hostname.find('@') >= 0:
username, hostname = hostname.split('@')
else:
hostname = raw_input('Hostname: ')
if len(hostname) == 0:
print '*** Hostname required.'
sys.exit(1)
port = 22
if hostname.find(':') >= 0:
hostname, portstr = hostname.split(':')
port = int(portstr)
# get username
if username == '':
default_username = getpass.getuser()
username = raw_input('Username [%s]: ' % default_username)
if len(username) == 0:
username = default_username
password = getpass.getpass('Password for %s@%s: ' % (username, hostname))
# get host key, if we know one
hostkeytype = None
hostkey = None
try:
host_keys = paramiko.util.load_host_keys(os.path.expanduser('~/.ssh/known_hosts'))
except IOError:
try:
# try ~/ssh/ too, because windows can't have a folder named ~/.ssh/
host_keys = paramiko.util.load_host_keys(os.path.expanduser('~/ssh/known_hosts'))
except IOError:
print '*** Unable to open host keys file'
host_keys = {}
if host_keys.has_key(hostname):
hostkeytype = host_keys[hostname].keys()[0]
hostkey = host_keys[hostname][hostkeytype]
print 'Using host key of type %s' % hostkeytype
# now, connect and use paramiko Transport to negotiate SSH2 across the connection
try:
t = paramiko.Transport((hostname, port))
t.connect(username=username, password=password, hostkey=hostkey)
chan = t.open_session()
chan.get_pty()
chan.invoke_shell()
print '*** Here we go!'
print
interactive.interactive_shell(chan)
chan.close()
t.close()
except Exception, e:
print '*** Caught exception: %s: %s' % (e.__class__, e)
traceback.print_exc()
try:
t.close()
except:
pass
sys.exit(1)
It gives error as follows :
Warning (from warnings module):
File "C:\Python26\li b\site-packages\Crypto \Hash\SHA.py", line 6
from sha import *
DeprecationWarn ing: the sha module is deprecated; use the hashlib module instead
Warning (from warnings module):
File "C:\Python26\li b\site-packages\Crypto \Hash\MD5.py", line 6
from md5 import *
DeprecationWarn ing: the md5 module is deprecated; use hashlib instead
Hostname: 10.135.15.41
Username [admin]: root
Warning (from warnings module):
File "C:\Python26\li b\getpass.py", line 88
return fallback_getpas s(prompt, stream)
GetPassWarning: Can not control echo on the terminal.
Warning: Password input may be echoed.
Password for root@10.135.15. 41: alcatel
*** Unable to open host keys file
*** Here we go!
Line-buffered terminal emulation. Press F6 or ^Z to send EOF.
Last login: Mon Dec 13 19:38:31 2010 from 10.135.19.50
*** Caught exception: <type 'exceptions.Att ributeError'>: read
Traceback (most recent call last):
File "C:\Python26\pa ramiko-1.7.4\demos\dem o_simple.py", line 90, in <module>
interactive.int eractive_shell( chan)
File "C:\Python26\pa ramiko-1.7.4\demos\int eractive.py", line 36, in interactive_she ll
windows_shell(c han)
File "C:\Python26\pa ramiko-1.7.4\demos\int eractive.py", line 91, in windows_shell
d = sys.stdin.read( 1)
File "C:\Python26\li b\idlelib\rpc.p y", line 560, in __getattr__
raise AttributeError, name
AttributeError: read
*** EOF ***
Traceback (most recent call last):
File "C:\Python26\pa ramiko-1.7.4\demos\dem o_simple.py", line 101, in <module>
sys.exit(1)
SystemExit: 1
can you tell me what is use of Hostkey and how to overcome this issue?!