SSH使用paramiko和exec_command

时间:2018-04-18 10:01:50

标签: python ssh paramiko

尝试使用SSH和paramiko从Windows服务器连接到Linux远程连接,并使用以下代码'pwd'此服务器(我已从实际代码更改了用户/密码和服务器IP):

import paramiko
from paramiko import SSHClient, AutoAddPolicy
LOCAL_IP=IP
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(LOCAL_IP,username=username, password=password)
client.exec_command('pwd')

我得到以下结果:

(<paramiko.ChannelFile from <paramiko.Channel 0 (open) window=24576 -> <paramiko.Transport at 0x6716710L (cipher aes128-ctr, 128 bits) (active; 1 open channel(s))>>>,
 <paramiko.ChannelFile from <paramiko.Channel 0 (open) window=24576 -> <paramiko.Transport at 0x6716710L (cipher aes128-ctr, 128 bits) (active; 1 open channel(s))>>>,
 <paramiko.ChannelFile from <paramiko.Channel 0 (open) window=24576 -> <paramiko.Transport at 0x6716710L (cipher aes128-ctr, 128 bits) (active; 1 open channel(s))>>>)

SSH连接已打开,我可以通过linux服务器上的netstat告诉我我正在尝试SSH ... ....

1 个答案:

答案 0 :(得分:1)

client.exec_command返回stdin,stdout和stderr流的元组 - 你需要分配这些并调用read()来获取输出:

plot.ellipse(
x='x',
y='y',
width=3,
height=3,
color='blue',
source=source
)