Paramiko Remote Control Module

Source: Internet
Author: User


Paramiko Remote Control module


Paramiko is a module for remote control, which can be used for command or file operation on a remote server . The remote management of fabric and ansible is the use of Paramiko to reality.


1. Download and install


# Pycrypto, since the Paramiko module is internally dependent on Pycrypto, download the installation first Pycrypto

# Download Install Pycrypto

wget http://files.cnblogs.com/files/wupeiqi/pycrypto-2.6.1.tar.gz

TAR-XVF pycrypto-2.6.1.tar.gz

CD pycrypto-2.6.1

Python setup.py Build

Python setup.py Install

# Enter the Python environment, import crypto to check if the installation was successful

# Download Install Paramiko

wget http://files.cnblogs.com/files/wupeiqi/paramiko-1.10.1.tar.gz

TAR-XVF paramiko-1.10.1.tar.gz

CD paramiko-1.10.1

Python setup.py Build

Python setup.py Install

# Enter the Python environment, import Paramiko to check if the installation was successful


2. Using the module

1) Execute command-connect to server via username and password

Import Paramiko

SSH = Paramiko. Sshclient ()

Ssh.set_missing_host_key_policy (Paramiko. Autoaddpolicy ())

Ssh.connect (' 192.168.1.108 ', 22, ' username ', ' password')

stdin, stdout, stderr = Ssh.exec_command (' DF ')

Print Stdout.read ()

Ssh.close ();


2) Execute command-over key link server

Import Paramiko

Private_key_path = '/home/auto/.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 (' hostname ', port, ' username ', key)


stdin, stdout, stderr = Ssh.exec_command (' DF ')

Print Stdout.read ()

Ssh.close ()


3) upload or download files-by user name and password

Import Os,sys

Import Paramiko


conn = Paramiko. Transport (' 192.168.20.21 ',())

Conn.connect (username= ' username ', password= ' password ')

SFTP = Paramiko. Sftpclient.from_transport (conn)

Sftp.put ('/tmp/test.py ', '/tmp/test.py ')

Conn.close ()


Import Os,sys

Import Paramiko


conn = Paramiko. Transport (' 192.168.20.21 ',())

Conn.connect (username= ' username ', password= ' password ')

conn = Paramiko. Sftpclient.from_transport (conn)

Sftp.get ('/tmp/test.py ', '/tmp/test2.py ')

Conn.close ()



4) upload or download files-via key


Import Paramiko


Pravie_key_path = '/home/auto/.ssh/id_rsa'

Key = Paramiko. Rsakey.from_private_key_file (Pravie_key_path)


conn = Paramiko. Transport (' 192.168.20.21 ',())

Conn.connect (username= ' username ', pkey=key)


SFTP = Paramiko. Sftpclient.from_transport (conn)

Sftp.put ('/tmp/test3.py ', '/tmp/test3.py ')


Conn.close ()


Import Paramiko


Pravie_key_path = '/home/auto/.ssh/id_rsa '

Key = Paramiko. Rsakey.from_private_key_file (Pravie_key_path)


conn = Paramiko. Transport (' 192.168.20.21 ',())

Conn.connect (username= ' username ', pkey=key)


SFTP = Paramiko. Sftpclient.from_transport (conn)

Sftp.get ('/tmp/test3.py ', '/tmp/test4.py ')


Conn.close ()


This article is from the "a myriad of simple pleasures of technology to enjoy" blog, please be sure to keep this source http://51enjoy.blog.51cto.com/8393791/1837839

Paramiko Remote Control Module

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.