Python3 use FABRIC3 module to implement key login remote host __python

Source: Internet
Author: User
Python3 FABRIC3 Module Implementation key Login

Go online search, found a pile of articles, such as the official website execution documentation, official website SSH use documentation, as well as official website password-management use documentation.

And all I want is to know how to use a key to link to a remote host. Easy, just look below.

Configure a fabfile.py file.

From FABRIC.API import *

env.hosts = [' 192.168.181.200 ']            # Specify hosts remote host
env.key_filename = '/path/to/id_ RSA '     # Specifies your private key file
Env.user = ' username '                    # Specify user name

def touchfile ():                         # Create a random task to test
    run (' Touch/ Tmp/www.txt ')
In writing Env.key_filename, in the Pycharm tool inside, and there is no automatic completion key_filename, not to say wrong or not, write directly on the can. As for why does not have the automatic completion, temporarily did not find the reason.

Executing commands on the command line

Fab touchfile

Output results:

[192.168.181.200] Executing task ' lspath '
[192.168.181.200] run:touch/tmp/www.txt done

.
Disconnecting from 192.168.181.200 ... Done.

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.