zoukankan      html  css  js  c++  java
  • 使用paramiko连接第一台服务器,并在第一台服务器上执行ssh连接第二台服务器,提示密码输入时的处理办法

    client = paramiko.SSHClient()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    client.connect(
    hostname='192.168.40.111',
    port=22,
    username='root',
    password='yourpass'
    )
    stdin, stdout, stderr = client.exec_command('ssh 192.168.40.158 "df -h"', get_pty=True)

    while not stdout.channel.exit_status_ready():
        temp = stdout.channel.recv(1024)
    result
    = temp.decode('utf-8').strip(' ')# 获取数据 if "continue connecting" in result: # 可能遇到询问是否添加指纹 stdout.channel.send("yes ") # 自动推送yes if "password:" in result: # 可能遇到询问密码 password_cmd = "%s " % yourpass # 自动推送密码(第二台服务器的密码) stdout.channel.send(password_cmd) else: print(result)

    if stdout.channel.exit_status_ready(): # 这里需要单独再判断一次,否则读取的数据可能少一部分 temp = stdout.channel.recv(1024) result = temp.decode('utf-8').strip(' ') print(result)

    break

  • 相关阅读:
    杭电ACM1.2.6 Decimal System
    杭电ACM1.2.7 GPA
    taro hook 倒计时setTimeout版
    taro hook 倒计时setInterval版
    Vuecli3内存溢出解决方案记录
    哈希
    hashmap和hashtable区别
    HashMap[转]
    JAVA中List、Map、Set
    C++和MATLAB混合编程DLL篇[转]
  • 原文地址:https://www.cnblogs.com/t-road/p/14470373.html
Copyright © 2011-2022 走看看