Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Use python to manage servers

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

#! / usr/bin/env python#coding:utf-8'''Paramiko install 1, install, download 1, download and install pycrypto-2.6.1.tar.gz (apt-get install python-dev), enter, python setup.py build [compile], python setup.py install [install]-"import Crypto 2, download and install paramiko-1.10.1.tar.gz, enter Python setup.py build [compiled] Python setup.py install [install]-- "import paramiko'''# specifies username password login import paramiko# instantiates an object ssh = paramiko.SSHClient () # verifies yes/nossh.set_missing_host_key_policy (paramiko.AutoAddPolicy ()) when ssh logs in # specifies the ip port password of the specified host ssh.connect ('192.168.1.108, 22,' alex', '123') # executes the command stdin, stdout Stderr = ssh.exec_command ('df') # read execution result print stdout.read () # disconnect ssh.close () # Login with key Private key login''before executing python, we now do some preparatory work on linux to generate the key ssh-keygen-t rsa remote copy own public key to specify the private key path to the other machine ssh-copy-id-I ~ / ssh/id_rsa.pub wupeiqi@192.168.159.129'''import paramiko# private_key_path =' / home/tom/.ssh/id_rsa'# to take out the private key key = paramiko.RSAKey.from_private_key_file ( Private_key_path) # the following is the same as logging in with a password ssh = paramiko.SSHClient () ssh.set_missing_host_key_policy (paramiko.AutoAddPolicy ()) ssh.connect ('182.92.219.96' 22, 'wupeiqi', pkey=key) stdin, stdout, stderr = ssh.exec_command (' df') print stdout.read () ssh.close ()

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report