Python Paramiko use

Source: Internet
Author: User

Paramiko Installation

Yum Install Python-paramiko-yyum install openssh-server openssh-clients-y

Error

Traceback (most recent): File "ssh.py", line ten, in <module> Ssh.connect (hostname=hostname,port=port,u    Sername=username,password=password) File "/usr/lib/python2.6/site-packages/paramiko/client.py", line 306, in Connect Self._policy.missing_host_key (self, hostname, server_key) File "/usr/lib/python2.6/site-packages/paramiko/ client.py ", line, Missing_host_key raise Sshexception (' Unknown server%s '% hostname) Paramiko. Sshexception:unknown Server 192.168.2.11


Workaround One

1. Create ~/.ssh/known_hosts

2, remote connection once

eg

#!/usr/bin/env pythonimport paramikohostname= ' 192.168.2.11 ' username= ' root ' password= ' Oracle ' port=22 Ssh=paramiko. Sshclient () Ssh.load_system_host_keys () Ssh.connect (hostname=hostname,port=port,username=username,password= Password) stdin,stdout,stderr=ssh.exec_command (' ls/') print Stdout.read () ssh.close ()


Workaround Two

Replace Ssh.load_system_host_keys () with Set_missing_host_key_policy (Paramiko. Autoaddpolicy ())

eg

#!/usr/bin/env pythonimport paramikohostname= ' 10.13.106.36 ' port=22username= ' root ' password= ' CentOS ' if __name__== ' _ _main__ ': Paramiko.util.log_to_file (' Paramiko.log ') S=paramiko. Sshclient () S.set_missing_host_key_policy (Paramiko.        Autoaddpolicy ()) S.connect (Hostname,port,username,password) stdin,stdout,stderr=s.exec_command (' Ifconfig ') Print Stdout.read () s.close ()


Reference post: http://emrys411876027.qj67.wshost.cc/python/69.html

Python Paramiko use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.