Python Paramiko analog SSH Login

Source: Internet
Author: User

Python Paramiko Module installation and use of the detailed

Http://www.111cn.net/phper/python/67973.htm

wget http://ftp.dlitz.net/pub/dlitz/crypto/pycrypto/pycrypto-2.6.tar.gz TAR-ZXVF pycrypto-2.6.tar.gz CD pycrypto-2.6/ python setup.py build python setup.py Install go to Python Import Crypto See if there are any errors apt-get install-y Python-paramiko you can then enter Python Import Paramiko See if there are any errors

Troubleshooting solution for installation process

http://blog.csdn.net/wang1144/article/details/42277179

#!/usr/bin/env python
#-*-Coding:utf-8-*-
Import Paramiko
Import Sys,os
Host = ' 10.74.85.167 '
user = ' Liqian '
Password = ' 123456 '
cmd = ' ls-l '
#绑定实例
s = Paramiko. Sshclient ()

#加载本机. ssh/knows_hosts file
S.load_system_host_keys ()

#第一次登陆机器需要输入yes, you don't have to enter it after you add it
S.set_missing_host_key_policy (Paramiko. Autoaddpolicy ())

S.connect (host,22,user,password,timeout=5)

#执行命令
Stdin,stdout,stderr = S.exec_command (cmd)

#错误输出和正确输出, there is only one output, either the correct output or the error output
Cmd_result = Stdout.read (), Stderr.read ()

#输出的结果逐行打印

For line in Cmd_result:

Print Line
S.close ()

Python Paramiko analog SSH Login

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.