Use of the Fort Machine python under SSH"Fortress machine More Reference" http://www.cnblogs.com/alex3714/articles/5286889.html"Demo instance of Paramiko" Https://github.com/paramiko/paramikoWin7 under Paramiko's demo telnet execute interactive command:"Download demo file" Https://github.com/paramiko/paramiko "Paramiko More Reference" Paramiko module learning Native [Win7] log on to a remote Linux server
Script in Github:https://github.com/linuxyan/linuxyan/tree/master/python/batch_create_pub_key
After downloading the script, first we have to set up the public key on the management machine, run the following command, all the way to return.
SSH-KEYGEN-T RSAAfter creating a good public key, let's look at the script.The batch_key.py and host.list are the documents we need.In Host.list, you save the account n
实例SFTP = Paramiko. Sftpclient.from_transport (Tran)#设置上传的本地/Remote file path#执行上传动作Sftp.put ("C:/7.der", "/tmp/7.der")Sftp.get ('/root/test.py ', ' f:/test.py ')Tran.close ()Issues that occur during the implementation:Import Paramiko appears unicodedecodeerror: ' ASCII ' codec can ' t decode byte 0xe9 in position 0:ordinal not in range (128) errorWorkaround: Under the Python installation path lib\site.py add the following code:Import SysReload (SYS)Sy
turning human-computer interaction into automatic interaction, and Python's Pexpect module can help us achieve automatic interaction. The following code is a function that implements the automatic interactive logon and execution of commands using Pexpect:
Copy Code code as follows:
#!/usr/bin/env python
#-*-Coding:utf-8-*-
Import Pexpect
def ssh_cmd (IP, passwd, cmd):
ret =-1
SSH
The examples in this article describe how Python monitors windows through Ssh-powershell. Share to everyone for your reference. The specific analysis is as follows:
For server monitoring, monitoring Linux Whether it's a do-it-yourself script or some open-source tool such as Nagios,zenoss or something. But after all, some companies have windows to do the server, relative to Linux, Windows is not convenient
The use of SSH in Python requires openssh, and OpenSSH relies on the Paramiko module, and the Paramiko module relies on the Pycrypto module, so to use SSH in Python, you need to first install the module order: Pycrypto- > ECDSA, Paramiko1, installation PycryptoInstalling this is cumbersome and requires local compilatio
When operating system maintenance, the SSH command is usually connected to the remote server for some operations. How to do this in Python, of course, can also execute SSH commands, but there is a more elegant way, with the help of Paramiko, which implements the SSHV2 protocol of an open source project, the following mainly uses its
Python decorator use example and actual application example, python example
Test 1
Deco is running, but myfunc is not running
Copy codeThe Code is as follows:Def deco (func ):Print 'before func'Return func
Def myfunc ():Print 'myfunc () called'Myfunc = deco (myfunc)
Test 2
Paramiko is a module written in the Python language that follows the SSH2 protocol and supports the connection of remote servers in a way that is encrypted and authenticated. Python's Paramiko module makes it easy to implement SSH logins and execute commands.1. Paramiko Module Installation 1.1 Install Pycrypto LibraryPlease poke here: http://download.csdn.net/detail/oatnehc/8825715;The home page of the Pycr
#!/usr/bin/envpython "need to pay attention to a few questions 1, Pxssh class, exist in the Pexpect module, if you do not install this module installed on its own, if this module already exists, but there is no pxssh class, verified, That is, the version of this module is too low. Please update to the new version 2, about the command in Os.system (), this is the execution of a shell command, and itself sshpass is implemented in the execution of the SCP file is to automatically enter the account
Http://blog.sina.com.cn/s/blog_53d874320102vdvu.html
Log in with the Python SSH module and execute shell commands on the remote machine
(in CentOS 7 The environmental test was successful, the Redhat series should be compatible.) )
Install the necessary modules first
# yum Install Python-dev
# yum Install Python-devel
There is no dedicated SSH module in Python, which requires a manual installation module. The use of SSH in Python requires openssh, while OpenSSH relies on Paramiko modules, and Paramiko modules rely on Pycrypto modules, so to use SSH in
Python Paramiko Module installation and use of the detailedHttp://www.111cn.net/phper/python/67973.htmwget http://ftp.dlitz.net/pub/dlitz/crypto/pycrypto/pycrypto-2.6.tar.gzTAR-ZXVF pycrypto-2.6.tar.gzCD pycrypto-2.6/python setup.py buildpython setup.py Installgo to PythonImport Crypto See if there are any errorsapt-get install-y
Multi-device Batch SSH command, is currently serial, later will join multithreading to achieve parallel, directly on the source code
Note You cannot perform dynamic commands such as top
#!/usr/bin/env python#-*-coding:utf-8-*-__author__ = ' babyshen ' __version__ = ' 1.0.0 ' Import Paramiko class SSh (object ): Def __init__ (self,port,username,password): Self.po
Single Sign-on:import paramikossh = paramiko.SSHClient()key = paramiko.AutoAddPolicy()ssh.set_missing_host_key_policy(key)ssh.connect(‘127.0.0.1‘, 22, ‘user‘, ‘passwd‘ ,timeout=5)stdin, stdout, stderr = ssh.exec_command(‘ls -l‘)for i in stdout.readlines(): print(i)For I in Stdout.readlines ():Print (i)These two paragraphs are output screen commands.If you have added a secret key login, leave passwd blank.Here are more than one server login:#!/usr/bin/pyth
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.