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/python# -*- coding: utf-8 -*-import time,shutil,osimport paramikoappname = "root"ssh = paramiko.SSHClient()key = paramiko.AutoAddPolicy()ssh.set_missing_host_key_policy(key)uptime = time.strftime("%Y%m%d")warpath="/var/tmp/cslc/aw/update/"+uptime+"/aw.war"def update_all_aw(): for line in open("awip.conf"): print line ssh.connect(line, 22, appname, ‘‘ ,timeout=5) stdin, stdout, stderr = ssh.exec_command(‘python /var/tmp/awpy/createcopy.py‘) for i in stdout.readlines(): print(i) print("+++++++下一个++++++") return
awip.conf file prevents multiple IP addresses.
Reference:
PYTHONSSH Remote Execute shell command
Python calls the Paramiko module for remote management of multiple servers
Python implements SSH remote login, and executes commands!
Python implements SSH remote login, and executes commands!
Linux remotely executes shell commands on Python using SSH