python下paramiko模块实现ssh连接登录Linux服务器

WBOY
Release: 2016-06-10 15:11:04
Original
1290 people have browsed it

本文实例讲述了python下paramiko模块实现ssh连接登录Linux服务器的方法。分享给大家供大家参考。具体分析如下:

python下有个paramiko模块,这个模块可以实现ssh登录linux服务器,下面贴出代码,注意,我在centos5.6下,python2.6.5,paramiko-1.7的版本下测试成功。

#!/usr/bin/env python
import paramiko
hostname='172.28.102.249'
username='root'
password='toor'
if __name__=='__main__':
  paramiko.util.log_to_file('paramiko.log')
  s=paramiko.SSHClient()
  s.load_system_host_keys()
  s.connect(hostname=hostname,username=username,password=password)
  stdin,stdout,stderr=s.exec_command('ifconfig;free;df')
  #这里我输了了多个命令,可以试验下
  print stdout.read()
  s.close()
Copy after login

希望本文所述对大家的Python程序设计有所帮助。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!