Monday, 15 September 2014

python - Django ssh failed during sftp connection -



python - Django ssh failed during sftp connection -

this error getting

ri@ri-desktop:~/workspace/ssh$ python ssh.py establishing ssh connection to: upload.partner.com 19321 ... failed loading ~/workspace/ssh/rsa_private_key no handlers found logger "paramiko.transport" trying ssh-agent key b747f6899b3a450e63bc6faab1625686 ... failed! key cannot used signing *** caught exception: <type 'exceptions.attributeerror'>: 'nonetype' object has no attribute 'get_fingerprint' ============================================================ total files copied: 0 operations complete! ============================================================ ri@ri-desktop:~/workspace/ssh$

this setup code. took setup code activstate . given right path , uncertainty firstly error showing failed loading ~/workspace/ssh/rsa_private_key. showing ssh-agent key failed that?

hostname = 'upload.partner.com' # remote hostname ssh server running port = 19321 username = 'music--test' password = 'grg' rsa_private_key = r"~/workspace/ssh/rsa_private_key" dir_local='~/workspace/ssh/new/' dir_remote = "remote_machine_folder/subfolder" glob_pattern='*.*' import os import glob import paramiko import md5 rsa = none def agent_auth(transport, username): ki = none #ppk = none effort authenticate given transport using of private keys available ssh agent or local private rsa key file (assumes no pass phrase). try: ki = paramiko.rsakey.from_private_key_file(rsa_private_key) except exception, e: print 'failed loading {0}'.format (rsa_private_key, e) agent = paramiko.agent() agent_keys = agent.get_keys() + (ki,) if len(agent_keys) == 0: homecoming key in agent_keys: print 'trying ssh-agent key {0}'.format(key.get_fingerprint().encode('hex')), try: transport.auth_publickey(username, key) print '... success!' homecoming except paramiko.sshexception, e: print '... failed!', e hostkeytype = none hostkey = none files_copied = 0 try: host_keys = paramiko.util.load_host_keys(os.path.expanduser('~/.ssh/known_hosts')) except ioerror: try: # seek ~/ssh/ too, e.g. on windows host_keys = paramiko.util.load_host_keys(os.path.expanduser('~/ssh/known_hosts')) except ioerror: print ' unable open host keys file' host_keys = {hostname:'upload.partner.com'} if hostname in host_keys: hostkeytype = host_keys[hostname].keys()[0] hostkey = host_keys[hostname][hostkeytype] print 'using host key of type {0}'.format(hostkeytype) try: print 'establishing ssh connection to:', hostname, port, '...' t = paramiko.transport((hostname, port)) t.connect() agent_auth(t, username) if not t.is_authenticated(): print 'rsa key auth failed! trying password login...' t.connect(username=username, password=password, hostkey=hostkey) else: sftp = t.open_session() sftp = paramiko.sftpclient.from_transport(t) try: sftp.mkdir(dir_remote) except ioerror, e: print '(assuming ', dir_remote, 'exists)', e fname in glob.glob(dir_local + os.sep + glob_pattern): is_up_to_date = false if fname.lower().endswith('xml'): local_file = os.path.join(dir_local, fname) remote_file = dir_remote + '/' + os.path.basename(fname) try: if sftp.stat(remote_file): local_file_data = open(local_file, "rb").read() remote_file_data = sftp.open(remote_file).read() md1 = md5.new(local_file_data).digest() md2 = md5.new(remote_file_data).digest() if md1 == md2: is_up_to_date = true print "unchanged:", os.path.basename(fname) else: print "modified:", os.path.basename(fname), except: print "new: ", os.path.basename(fname), if not is_up_to_date: print 'copying', local_file, 'to ', remote_file sftp.put(local_file, remote_file) files_copied += 1 t.close() except exception, e: print '*** caught exception: %s: %s' % (e.__class__, e) try: t.close() except: pass print '=' * 60 print 'total files copied:',files_copied print 'all operations complete!' print '=' * 60

can help me solve error

edit after much , fro, solution add together user's private key ssh agent via ssh-add.

actually, might trying utilize public key, not private key.

the file name "id-rsa.pub" looks suspiciously public key. corresponding private key named "id-rsa". public keys this:

ssh-rsa aaaab3nzac1yc2eaaaadaqabaaabaqcumhzlysqqmzcgge0nkwyyylphb3g1bwdll2ztnguwnkrdswgmlq6iqjp9ewwxungwjkdkr/u86gfv5mqfq92+0ote7puxoacwhfqviouxxfi3zlo/c2cuqdio7fco50kkgfauwbjtd3rugbpomnnqt99wz/1lrcktsjld0yxtro/qsj8jizxruaezbdxkwzjap8g3ebhsmiea1781ywklk50xxlk2qtpwvzen+om6inbq2cr6bbvfia4b3les53ccmmfzrcygjl8b6yav3ni60re5ondynrpzgh4vxf5p4vwrkpy4dccjzynmhlfhjltgzu25ukabp8wk4u1ky0vj mhawke@localhost.localdomain

whereas unencypted private keys this:

-----begin rsa private key----- miicxqibaakbgqcfqblok4vec7r0df4a2cynzmhjn74qidqbjnkgashcn5/gyudv . . xlcnrvmxypd1i7l5ngzzalatrs+dkglwnvghkvgkugao -----end rsa private key-----

and encrypted private keys this:

-----begin rsa private key----- proc-type: 4,encrypted dek-info: aes-128-cbc,1acd09b7f078aeb84b9a109979b77cbb ldeuf08/xmgshyeszxfgkrnhf8c78vpddjybbmanot/mrf/5fkjoel8rgoh4oyez . . tkjd+plr4wllumpfehujdqhvyc4fqefzwqak+rlug5o3lm+tackqjypaeu4rvuuw -----end rsa private key-----

check see if using right key file. can test by:

openssl rsa -text -noout -in private_key_file

you shouldn't see errors.

python linux ssh sftp paramiko

No comments:

Post a Comment