无法使用python paramiko

时间:2018-12-26 15:04:10

标签: python-3.x bash paramiko aws-cli

问题:

我正在尝试使用python paramiko在远程主机上配置AWS配置文件。

我的代码可以连接到服务器并能够执行命令。但是无法将输入一一传递给命令“ aws configure”。

代码:

import paramiko
import sys

ip = 'x.x.x.x'
port = 22
username = 'test'
password = "123"
command = "aws configure --profile user1"

ssh=paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip,port,username,password)
stdin,stdout,stderr=ssh.exec_command(command)
stdin.write(id+ '\n')
stdin.write(key+ '\n')
stdin.write('us-east-1'+ '\n')
stdin.write(''+ '\n')
stdin.flush()
print(stdout.read().decode())
ssh.close()

输出:得到一个空白输出,当我SSH服务器并运行“ aws configure list”以检查是否配置了aws时,然后显示以下输出字段

    Name                    Value             Type    Location
    ----                    -----             ----    --------
   profile                <not set>             None    None
access_key                <not set>             None    None
secret_key                <not set>             None    None
    region                <not set>             None    None

我无法理解我在哪里犯错,无法在Sshed主机上配置AWS。请通过修改代码提供解决方案,谢谢!!!

0 个答案:

没有答案