Using the Python Management Server

Source: Internet
Author: User

#!/usr/bin/env python#coding:utf-8 "paramiko  install one, install, download 1, download and install  pycrypto-2.6.1.tar.gz (apt-get  install python-dev) Unzip, enter, Python setup.py build "compile", Python setup.py install   Install   ----import crypto 2, download and install  paramiko-1.10.1.tar.gz extract, enter, python setup.py  build "Compiling",python setup.py install  "Installation"---"  import paramiko" # Specifies the user name password to log import paramiko# instantiate an object Ssh = paramiko. Sshclient () #验证ssh登陆时的yes/nossh.set_missing_host_key_policy (Paramiko. Autoaddpolicy ()) #指定主机的ip   Port   user name   password ssh.connect (' 192.168.1.108 ', 22,  ' Alex ',  ' 123 ' ) #执行命令stdin,  stdout, stderr = ssh.exec_command (' df ') #读取执行结果print  stdout.read () # Disconnect Ssh.close () #使用密钥方式登录, private key Login "' Execute python before   now do some preparatory work on Linux generate key ssh-keygen -t  RSA remote copy its own public key to the other machine ssh-copy-id -i ~/ssh/id_rsa.pub [email protected] "' import  paramiko# Specifies the private key path Private_key_path =  '/home/tom/.ssh/id_rsa ' #取出私钥key  = paramiko. Rsakey.from_private_key_file (Private_key_path) #下面和使用密码登录步骤一样ssh  = paramiko. Sshclient () Ssh.set_missing_host_key_policy (Paramiko. Autoaddpolicy ()) ssh.connect (' 182.92.219.96  ', 22,  ' Wupeiqi ',  pkey=key) stdin, stdout,  stderr = ssh.exec_command (' DF ') Print stdout.read () Ssh.close ();


This article comes from the "Python&linux's blog" blog, please be sure to keep this source http://topping.blog.51cto.com/12388701/1934468

Using the Python Management Server

Related Article

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.